NetworkIdentity SceneID, AssetID, and Observer issues

Hey there,

I’m not entirely sure if this is the right forum, as these issues aren’t necessarily 5.2 exclusive, but I’ve been using strictly beta versions for the development of my game since 5.1, due to all the nice features you guys keep adding. That aside, these are some of the issues I’ve run into using UNet. If necessary, I can try to create a bug report with a repro project, but I’m not sure if these are bugs, and I’d rather not waste my time :smile:

  1. The SceneID of a NetworkIdentity loaded from a scene can be changed using ForceSceneID. However, if another scene is loaded (at least in my case, using LoadLevelAdditive), the SceneID is changed from 0 to 1 (in my case, maybe it just gets reset to the old ID?), and the GameObject is marked inactive, regardless of the previous status. If it has any impact, these scenes are loaded from asset bundles.

  2. There is no way to set the AssetID for a NetworkIdentity outside of doing Spawn() and then Unspawn(). This makes it hard to simply instantiate a new object and spawn it, in the event that we develop prefabs at run-time. In my case, I am loading prefab assets from an asset bundle, building a deterministic asset ID (but avoiding collisions), and then registering spawn handlers. It would be simpler to not manage a dictionary on my own, and simply use RegisterPrefab, but you cannot do so without setting the asset ID first.

  3. I’ve noticed that if you call RebuildObservers(), you are able to add a connection to the observer list before it is ready. However, because the connection is not ready, the spawn message is not sent to the client, and because it is already an observer, OnCheckObserver() gives a warning that the observer was already added. This results in the object never being sent to the client at all. While I’ve already worked around the issue on my own, trying to figure out the cause took quite some time and was very frustrating, so maybe something to avoid for others :smile:

The beta forum is targeted regarding specific work for the beta. Not regressions or issues from prior versions. Shifting to the Networking forum accordingly.

  1. hm… ForceSceneId should really be internal, not public. It is used during scene post-processing, and is not intended for use at runtime. Support for LoadLevelAdditive() with scene objects is on our TODO list, but is not supported by the current system. At very least, it currently does not deal with sceneId conflicts between the scenes.

  2. Would “void RegisterPrefab(GameObject prefab, NetworkHash128 assetId)” solve this? That would set the assetId on the object.

  3. I will file a bug on that

So then the SceneID is just an internal thing that doesn’t have an impact on spawning? To clarify, the reason I was setting it was because of a console error, though, admittedly, the objects did all spawn exactly as desired. My goal in forcing the ID was just to remove it entirely, as my entire game exists in a single scene, and the only reason I’m loading scenes at all is to allow for dynamic prefabs, as defined by my modding system (all of which works great right now I might add!)

This would work just fine!

Great! As a side-note, keep up the great work! Having spent the majority of my career working on an MMO, I really appreciate how fully-featured the UNET HLAPI is. It’s always good when the system you want to create already exists, for free, integrated into the engine.

1 Like

As an addendum to the scene ID thing, I realized I made a small mistake when explaining my use case. Although my assets are all loaded from bundle scenes, all of the NetworkIdentity and NetworkBehaviour components are added at run-time. Initially, after the NetworkIdentity component is added, they are given a scene ID of 0. However, once I call LoadLevelAdditive, they are assigned a scene ID of 1. I’m not sure if this changes anything, but I thought it might be worth mentioning.

Please advise when and how to use http://docs.unity3d.com/ScriptReference/Networking.NetworkIdentity.ForceSceneId.html
It just won’t change on client, entire object goes disabled and won’t trigger even in Awake() while being first in script execution order.
I really need it because every time i hit “save scene” it’s scrambling scene IDs so i have to push new server build and update clients on every device.