I’m struggling to find a solid answer on what seems should be a pretty standard use-case: spawning a network object with particular params specified by the server.
I expected to be able to :
- Instantiate (on server)
- Set network variables
- Spawn (I hoped spawning would propagate the net variables)
However, in doing this I get the warning:
NetworkVariable is written to, but doesn’t know its NetworkBehaviour yet. Are you modifying a NetworkVariable before the NetworkObject is spawned?
Is there any way to do this cleanly?
I can think of some workarounds; however, they all seem pretty painful:
Send the initial params from the server OnNetworkSpawn:
- Spawn the object in a “hidden” state
- Set the initial param values in “OnNetworkSpawn” on the server, and also set a “hasBeenInitiailsed” flag
- Upon this flag being set, show the object on the client
…Presumably this is likely to result in object appearing probably a few frames late
Prespawn the object, and then use an RPC to enable it
Keep a pool of pre-spawned objects that are somehow hidden. Then, instead of needing to spawn an object, the server just switches one on, either via a network variable, or an RPC.
This seems like a lot of unnecessary work, particularly if pooling is not actually required for any other reason (e.g. it’s an object that is spawned rarely).
Any thoughts?