The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our

Please check if you can find an answer in our extensive documentation on Fusion.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Best Practices for Initializing State and Determining Local vs. Remote Spawned Objects?

2022-11-13 01:39:43


I'm finding the Fusion documentation a bit ambiguous and wanted to clarify a few things.

  • OnBeforeSpawn always runs on the server. Is it safe to assume that any Networked properties that I initialize here will be set when Spawned() is called on the remote side? I assume that Photon ships over the initial state snapshot when sending a spawn request to clients.

  • What is the best practice for identifying whether an instance of a spawned object is "local" (that is, represents something on the given client) or not? For example, I am spawning avatars. Local avatars are driven by the local user's machine so I need to know which objects these are. Currently, I'm setting a Networked property for the player ID in OnBeforeSpawn(). Then, in Spawned(), I set: _isLocal = _netObj.Runner.LocalPlayer.PlayerId == _playerID. Where _netObj is the NetworkObject.

  • Is there any callback we can listen to to detect that an object has been spawned on a client (in order to e.g., initialize it)? Again, in my case, my prefab has some fields that need to be populated at run-time. Rather than having the scripts on the prefab itself search for these, it seems cleaner to have some callback that informs me the object has been spawned.




Back to top