Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

5.6 UNET Prefab linked GameObjects within the scene

Discussion in 'UNet' started by webjeff, Apr 2, 2017.

  1. webjeff

    webjeff

    Joined:
    Mar 11, 2015
    Posts:
    39
    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...

    Code (csharp):
    1.  
    2.        static bool CheckForPrefab(GameObject obj)
    3.         {
    4. #if UNITY_EDITOR
    5.             return (UnityEditor.PrefabUtility.GetPrefabParent(obj) == null) && (UnityEditor.PrefabUtility.GetPrefabObject(obj) != null);
    6. #else
    7.             return false;
    8. #endif
    9.         }
    10.         static bool VerifyCanSpawn(GameObject obj)
    11.         {
    12.             if (CheckForPrefab(obj))
    13.             {
    14.                 Debug.LogErrorFormat("GameObject {0} is a prefab, it can't be spawned. This will cause errors in builds.", obj.name);
    15.                 return false;
    16.             }
    17.             return true;
    18.         }
    19.  
     
  2. Epiplon

    Epiplon

    Joined:
    Jun 17, 2013
    Posts:
    52
    This is also happening with me with the Player Prefab and objects that aren't even in the Hierarchy, it makes 0 sense.
     
  3. webjeff

    webjeff

    Joined:
    Mar 11, 2015
    Posts:
    39
    *bump* - Hate to bump, but does anyone have an idea on this?
     
  4. Nitrousek

    Nitrousek

    Joined:
    Jan 31, 2016
    Posts:
    38
    Seems like a bug - makes zero sense to me, and I've been networking for a while.
     
  5. meti314

    meti314

    Joined:
    Sep 30, 2015
    Posts:
    3
    I have the same problem and no clue what is happening. If it's a bug I hope it will be fixed soon.
     
  6. Dee_Lucky

    Dee_Lucky

    Joined:
    Jun 26, 2015
    Posts:
    53
    Got the same error, it will be fixed in patch I guess.
     
  7. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,173
    I also get this problem, can someone from Unity comment as i am not able to continue working due to this error???
     
  8. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,173
    I redid the prefabs and then it worked.
     
    wmadwand likes this.
  9. MichalBUnity

    MichalBUnity

    Unity Technologies

    Joined:
    May 9, 2016
    Posts:
    18
    The check was added because you cannot spawn a prefab. You need to instantiate it first. e.g.

    Code (CSharp):
    1. public GameObject treePrefab;
    2.  
    3. public void Spawn()
    4.     {
    5.         GameObject tree = (GameObject)Instantiate(treePrefab, transform.position, transform.rotation);
    6.         NetworkServer.Spawn(tree); //works
    7.         NetworkServer.Spawn(treePrefab);  // gives error
    8.     }
     
    Logophile and pKallv like this.
  10. Nitrousek

    Nitrousek

    Joined:
    Jan 31, 2016
    Posts:
    38
    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.
     
  11. Epiplon

    Epiplon

    Joined:
    Jun 17, 2013
    Posts:
    52
    And for me, it is raising this error with the Player prefab and a default Network Manager.
     
  12. pappaxray2

    pappaxray2

    Joined:
    Mar 30, 2016
    Posts:
    11
    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.
     
  13. op6yz

    op6yz

    Joined:
    Apr 14, 2015
    Posts:
    3
    LOL. This works for me! o_O Thank you.
     
  14. wmadwand

    wmadwand

    Joined:
    Jul 19, 2014
    Posts:
    14
    Simply done the same thing and it's worked like a charm. That is to say got the error fixed now. Cheers, folks!
     
    Last edited: Apr 22, 2017
  15. webjeff

    webjeff

    Joined:
    Mar 11, 2015
    Posts:
    39
    This worked for me! Thanks!
     
  16. The-Suspense

    The-Suspense

    Joined:
    Apr 13, 2017
    Posts:
    1


    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?
     
  17. Hiinas

    Hiinas

    Joined:
    Dec 30, 2016
    Posts:
    21
    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.
     
  18. Islingr

    Islingr

    Joined:
    Jun 27, 2013
    Posts:
    3
    Wow, that was it! Thank you so much, I was just about to cry because of this error. Thanks again!
     
  19. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71

    How can you change that? I'm using Unity 5.6
     
  20. Epiplon

    Epiplon

    Joined:
    Jun 17, 2013
    Posts:
    52
    You can see those settings by setting Debug on the Inspector.
     
  21. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    Sorry for a trivial question, how do I debug on the inspector?
    I know how to Debug.Log functions from C#.
     
  22. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    At the inspector, there's an icon to the right of the "lock".
    debug.PNG
    Press it, in the context menu select "Debug".
     
  23. Eco-Editor

    Eco-Editor

    Joined:
    Jun 29, 2016
    Posts:
    71
    Thanks! This fixed the error :)
     
  24. joecarver

    joecarver

    Joined:
    Mar 7, 2017
    Posts:
    2
    for me, resetting the network identity component fixed all problems
     
  25. Ggabe

    Ggabe

    Joined:
    Sep 20, 2015
    Posts:
    4
    Removing all scripts and the NetworkIdentity component and then adding them all back worked for me.
     
  26. kaleidosgu

    kaleidosgu

    Joined:
    Jan 8, 2017
    Posts:
    5
    Thank you pappaxray2. Your solution is correctly.
    The reason of problem is someone change the prefab value or scene content. The sceneId related the gameobject. When unity spawn something through the sceneid found the prefab item.
    After I change the sceneid of the prefab then apply it. Unity will find the right object.
     
  27. phygitalmadhouse

    phygitalmadhouse

    Joined:
    Jan 19, 2017
    Posts:
    12
    ;) Mine was due this issue , i was instantiating the "treePrefab" , not the instantiated tree.