DontDestroyOnLoad
(DDOL) in Awake.
You can do that in Start instead.NetworkServer.Spawn
function to spawn game objects with Network Identity components. Spawning them this way assigns them a netId
and creates them on clients connected to the server.NetworkBehaviour
(instead of the default MonoBehaviour
), then you can add your script as a component to a game object.OnStartClient
for the player game object on the local clientOnStopClient
for the player game object on the local clienthasAuthority
will be true for such objects in client context.OnStartServer
and OnStartClient
are called on the same game object. Both these functions are useful for actions that are specific to either the client or server, such as suppressing effects on a server, or setting up client-side events.[Server]
and [ServerCallback]
return immediately if the client is not active. Likewise, [Client]
and [ClientCallback]
return immediately if the server is not active.[Server]
and [Client]
attributes do not generate compile time errors, but they do emit a warning log message if called in the wrong context.ServerCallback
and ClientCallback
attributes act the same as above but do not cause a warning to be generated.Cmd
so it's easier to recognize in your calling code what will be happening.[ClientRpc]
. While not required, it is strongly suggested to prefix method names with Rpc
so it's easier to recognize in your calling code what will be happening.Event
SyncEvent
attribute