Open HeyZoos opened 3 years ago
It doesn't look like the Spawn
system makes any effort to inspect a prefabs children?
NetworkIdentity identity = GetComponent<NetworkIdentity>(entity);
if (identity.netId == 0)
{
// set netId to Entity's unique id (Index + Version)
// there is no reason to generate a new unique id if we already
// have one. this is way easier to debug as well.
// -> on server, netId is simply the entity.UniqueId()
// -> on client, it's a unique Id from the server
identity.netId = entity.UniqueId();
// set the owner connectionId
identity.connectionId = ownerConnectionId;
// apply component changes
SetComponent(entity, identity);
The NetworkIdentity
s, when nested end up with the same prefabId
s as the parent NetworkIdentity
The issue is here in NetworkIdentityAuthoring.cs
:
// is this a prefab? then assign prefab's Guid
if (PrefabUtility.IsPartOfPrefabAsset(gameObject))
{
string path = AssetDatabase.GetAssetPath(gameObject);
AssetDatabase.GetAssetPath(gameObject)
will return the same path for both the parent NetworkIdentity
component and a nested NetworkIdentity
component.
And because these are the same, when the server sends a spawn message, it tells the client to spawn multiple of the parent.
Describe the bug
Spawning a prefab with nested
NetworkIdentity
s results in extra entities and nonetId
to be set.To Reproduce Steps to reproduce the behavior:
1) Create a fresh unity project and add DOTSNET 2) Create a prefab with a
NetworkIdentity
, call itParent
3) Create another prefab with aNetworkIdentity
and nest it under parent, add a visual representation if you wantYour prefabs should now look like this
4) Trigger a spawn by hooking into one of the existing systems (I hooked into the chat system message server system)
Expected behavior Occurs when spawning untested child prefab, only 10 entities spawn client-side and all have unique
netId
valuesActual behavior Hundreds of extra client-side entities all with
netId
set to 0Desktop (please complete the following information):