5.6 UNET Prefab linked GameObjects within the scene

Hello,

In the 5.6 version, I noticed UNET now throw some errors when it calls StartHost:

“GameObject X is a prefab, it can’t be spawned. This will cause errors in builds.”

However, these are objects in my scene that are GameObjects dragged in from prefabs. They have the NetworkIdentity component. When I break the link from the prefab, the errors did go away, but I can’t understand why they can’t be originated from a prefab. Is this a bug or is there a reason for this?

Here’s the code in UNET related to this…

       static bool CheckForPrefab(GameObject obj)
        {
#if UNITY_EDITOR
            return (UnityEditor.PrefabUtility.GetPrefabParent(obj) == null) && (UnityEditor.PrefabUtility.GetPrefabObject(obj) != null);
#else
            return false;
#endif
        }
        static bool VerifyCanSpawn(GameObject obj)
        {
            if (CheckForPrefab(obj))
            {
                Debug.LogErrorFormat("GameObject {0} is a prefab, it can't be spawned. This will cause errors in builds.", obj.name);
                return false;
            }
            return true;
        }

This is also happening with me with the Player Prefab and objects that aren’t even in the Hierarchy, it makes 0 sense.

bump - Hate to bump, but does anyone have an idea on this?

Seems like a bug - makes zero sense to me, and I’ve been networking for a while.

I have the same problem and no clue what is happening. If it’s a bug I hope it will be fixed soon.

Got the same error, it will be fixed in patch I guess.

I also get this problem, can someone from Unity comment as i am not able to continue working due to this error???

I redid the prefabs and then it worked.

1 Like

The check was added because you cannot spawn a prefab. You need to instantiate it first. e.g.

public GameObject treePrefab;

public void Spawn()
    {
        GameObject tree = (GameObject)Instantiate(treePrefab, transform.position, transform.rotation);
        NetworkServer.Spawn(tree); //works
        NetworkServer.Spawn(treePrefab);  // gives error
    }
2 Likes

Yeah, great, but it was happening when I wasn’t even spawning anything. Just a random prefab in the scene, like my ParticleManager, just randomly started giving those errors. Once I deleted the prefab it started working again…

  • It is not instantiated by code at any point, it exists in the scene.

And for me, it is raising this error with the Player prefab and a default Network Manager.

What I did was, in the network identity component there was:
m_SceneId:
m_Value: 44
For all other prefabs this was 0, I changed it to zero and the error disappeared.

I think this happens if you have an object where the value has changed and then apply it’s properties to the prefab.

6 Likes

LOL. This works for me! :eyes: Thank you.

Simply done the same thing and it’s worked like a charm. That is to say got the error fixed now. Cheers, folks!

This worked for me! Thanks!

I’m very sorry but I’m really new to unity and the update just demolished my school project, so could someone explain to me What i’m supposed to do to fix this?

On the object that is throwing the error. Try removing the Network Identity component and then add it again. Worked fine on my player prefab.

Wow, that was it! Thank you so much, I was just about to cry because of this error. Thanks again!

How can you change that? I’m using Unity 5.6

You can see those settings by setting Debug on the Inspector.