Search Unity

Having a strange problem with Prefabs

Discussion in 'Editor & General Support' started by Yarbius, Jun 29, 2015.

  1. Yarbius

    Yarbius

    Joined:
    Apr 29, 2014
    Posts:
    22
    I am very worried something is corrupt in my project. I am making a 2d top-down rogue-like and am currently using prefabs to generate enemies from. I have started running into an issue where I get a null reference error when trying to iterate a collection of enemies after doing anything on the prefabs, even just selecting one in the editor. If I drag any of the enemy prefabs into the scene then immediately delete it I am fine until I touch a prefab in the inspector again. at one point I was getting "iHasError" 6 times with no info but the unity reinstall fixed that so far

    I have tried:
    • Deleting the library folder
    • Doing a Reimport All
    • Uninstalling and reinstalling Unity
    • Reloading the project from a few days ago
    • Removed a bunch of animations added this weekend
    • Commenting out everything I had done recently in the Enemy script
    • Googled for a couple hours and looking for things that seem similar
    My prefab is structured:
    • Gameobject
    • Sprite Renderer
    • Enemy (Script) About 500 lines
    • Animator (simple 2-sprite swap animation)
    Does anyone have any ideas?

    Mike B
     
  2. Yarbius

    Yarbius

    Joined:
    Apr 29, 2014
    Posts:
    22
    Tried installing 5.1.1p2, same problem....
     
  3. Yarbius

    Yarbius

    Joined:
    Apr 29, 2014
    Posts:
    22
    OK through test, trial and torture I have found that if I remove the "Enemy" Tag from the prefab that it does not cause this error. The only problem is I need to use FindGameObjectsWithTag("Enemy") to build a collection. I tried making a new tag but that did the same thing. I created a new folder in prefabs and created a new prefab from scratch and everything worked fine until I added the tag.

    I'm not sure where to go from here. Any ideas what I should try next?

    Mike
     
  4. Desprez

    Desprez

    Joined:
    Aug 31, 2012
    Posts:
    305
    I seem to be having a tag problem with prefabs as well.
    If i change some variables in a script of a prefab, and if the script component is still in the inspector when hitting play, an invisible clone of the instantiated prefab is causing problems in the scene. But the invisible object only seems to be detected when using FindObjectsWithTag.
    See: http://forum.unity3d.com/threads/serialization-prefab-bug.335877/#post-2180931

    No idea how much these problems are related.
     
  5. Yarbius

    Yarbius

    Joined:
    Apr 29, 2014
    Posts:
    22
    I looked at your thread and it is exactly the same problem, you are just farther along in constraining the conditions that cause it. I'll make any further posts regarding this on your thread so things are consolidated.

    Thanks

    PS Love the name Mob Farm!