Hi All,
I have come across a scenario where I want to network spawn objects on the host but I don’t want it to progress as per Object Creation Flow (https://docs.unity3d.com/Manual/UNetSpawning.html). The main reason is that the object being created may only be relevant to a few players and sending the network traffic would be redundant as the second that observers are rebuilt the object would no longer be relevant.
Is there a way to spawn an object on the host and stop it from pushing all its data out and just let the clients pick it up in the next observer rebuild?
I haven’t included any code at this point as I am asking in the abstract sense but let me know if it help for answering the question.
I don’t think it’s possible to have control over NetworkIdentity.observers (to my knowledge). Observers are added/removed automatically and I do not believe you can control them. The networked object must be either
-Visible only to server (NetworkIdentity.ServerOnly = true)
-Visible to all clients
If you only want to send data to certain clients I think you must use UNET messages (or possibly TargetRPC).
By setting OnCheckObserver to false automatically means that when any object is spawned it is not transmitted to any clients until they are a listed observer. I have not proven this though so if someone could confirm that would be great. It also means that the Object Creation Flow documentation should be updated to clarify this too.
I wasn’t aware of that, thanks. The biggest problem I’ve had by far is NetworkIdentity.observers being removed & re-added during scene change for persistent objects that are carried from one scene to the next. This causes a variety of bugs (SyncVars/SyncLists de-syncing, hooks failing, RPC’s failing, OnSerialize/Deserialize called repeatedly, etc.). Can you prevent that from happening?
In my case I am not doing any scene reloading as I am doing a sandbox so my requirements is to have proc gen chunks getting sent to the players that have an interest.
Have you looked at using the OnLevelWasLoaded you could use this as a bit of a reset between scenes for you persistent objects or maybe test if OnStartClient is fired again. If so you could do something like have a bool for once the object is ready again and just return out of your methods until it is “ready” then carry on.
May need to look at it case by case but happy to help if you have some examples.