FirstGearGames / FishNet

FishNet: Unity Networking Evolved.
Other
1.32k stars 139 forks source link

PrefabId 65535 is out of range when spawning nested prefab network objects #778

Open Rob-Kilgore opened 5 days ago

Rob-Kilgore commented 5 days ago

General Unity version: 2022.3.30f1 Fish-Networking version: 4.4.5 Pro Discord link: https://discord.com/channels/424284635074134018/1279073515139502112/1279073515139502112 (Discord Username is markclark, please let me know if I can provide further info)

Description When spawning a prefab with nested network objects, I get 2 exceptions with messages "PrefabId 65535 is out of range." and "NullReferenceException: Object reference not set to an instance of an object".

I have reproduced this with a function as simple as the following in OnStartServer on a script in my online scene where toSpawn is my nested network object:

public override void OnStartServer()
{
    NetworkObject go = Instantiate(toSpawn);
    Spawn(go);
}

If I switch the prefab to a flat Game Object (No nested network objects), then there is no exception

Replication Steps to reproduce the behavior:

  1. Create a Game object with a network object script on it
  2. Add a child Game Object with another network object script on it
  3. Save the Game Object from (1) as a Prefab
  4. Create a script on a scene object to spawn the network object from (3) in OnStartServer
  5. Run the game and load the scene

Expected behavior The object should spawn without error

Actual behavior The object causes 2 exceptions on spawn

Screenshots image stacktrace2.txt stacktrace1.txt

FirstGearGames commented 5 days ago

I was not able to reproduce this. Please provide a project doing so and this will be looked into. https://fish-networking.gitbook.io/docs/manual/guides/creating-bug-reports#guidelines

Rob-Kilgore commented 5 days ago

Here's a unitypackage with what I used to reproduce this issue. The project had only these files & a stock FishNet installation. Note the difference between setting the toSpawn parameter of the Object Spawner component in OnlineScene to NestedPrefab or NormalPrefab. PrefabBugReport.zip

Eonasdan commented 4 days ago

This is happening to me too, with this same prefab ID.

I'm just using the NetworkManager and dropping a prefab on to the "Player Prefab" field.

The po here has a single prefab with an ID of 0. There are a couple of calls to this where the code is looking for id of 0 and that works just fine. Then there's a call looking for ID 65535, which doesn't exist.

 PrefabObjects po = NetworkManager.GetPrefabObjects<PrefabObjects>(nob.SpawnableCollectionId, false);
                tpf = nob.GetTransformChanges(po.GetObject(asServer: true, nob.PrefabId)

I also tried creating my own spawnables SO, but that didn't resolve it. Strangely, I had it working with a different spawn prefab.

Edit: The original prefab I had working no longer works. Same error. I created plain sphere object, slapped a network transform on there and set that to the player prefab and that works. Of course, it doesn't do anything but the client at least starts.

I'm using v4.4.5R

Eonasdan commented 3 days ago

@Rob-Kilgore I think I figured it out. I had a prefab like this RootObject. I added some debugging to the FishNet code where it was breaking and discovered that 65535 is just public const int UNSET_PREFABID_VALUE = ushort.MaxValue; when the PrefabId wasn't set. I logged the name of the game objects to find that the problem was on Child. Once I removed the NetworkObject component from Child (see Child2). It looks like the problem went away.

classDiagram
    RootObject <|-- Child
    RootObject2 <|-- Child2
    class RootObject{
      NetworkObject
    }
    class Child{
      NetworkObject
      NetworkAnimator
      NetworkTransform
    }
    class RootObject2{
      NetworkObject
    }
    class Child2{
      NetworkAnimator
      NetworkTransform
    }
FREEZX commented 12 hours ago

This prevents me from upgrading to the latest version, breaks my game.