Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Destroy Immediate has broken my prefab, apparently

Discussion in 'Editor & General Support' started by gmaasry, Mar 7, 2023.

  1. gmaasry

    gmaasry

    Joined:
    Nov 19, 2022
    Posts:
    2
    I recently tried to use DestroyImmediate to remove an instantiated object in my game, despite Unity's warning. After running and the script's execution, Unity threw some error. I removed the DestroyImmediate line of code, but then Unity started throwing a new error saying some asset no longer existed. Now I am in a situation where it seems like my most important prefab -- the same object type that I was trying to destroy -- is *permanently broken* in my editor. When I try to create a new prefab variant based on it, that variant simply refuses to instantiate itself normally during normal gameplay. The prefab variants I had already built prior are still working fine, for some reason.

    Can anyone explain what is going on here? Is my prefab actually broken? How can I undo whatever stupidity Unity has concocted. As this is my first time posting a question please feel free to tell me what information I can provide further. I don't know that posting snippets of code will help here since nothing is ostensibly wrong with my scripts; it's just that my prefab is somehow broken in a way I don't understand. Can someone explain what DestroyImmediate is actually doing? How is it possible that it destroyed my prefab sitting inside the editor just by running a run-time script once? How can I tell what is broken? Upon inspection the prefab looks perfect ... it just fails to do anything during runtime.

    Thank you
     
  2. gmaasry

    gmaasry

    Joined:
    Nov 19, 2022
    Posts:
    2
    (I don't understand this still but this can be marked as RESOLVED as I fixed the problem). Thank you.