Z
Z
Zimaell2020-10-01 13:51:39
Unity
Zimaell, 2020-10-01 13:51:39

What to do if prefabs are not loaded after DestroyImmediate?

the code worked normally, everything was displayed normally

GameObject Prefab = null;
string LoadPrefab = "Test/Test1";
if(Resources.Load(LoadPrefab, typeof(GameObject)) as GameObject!=null){
  Prefab = Resources.Load(LoadPrefab, typeof(GameObject)) as GameObject;
  ObjectsList[id] = Instantiate(Prefab, new Vector3(0, 0, 0), Quaternion.identity);
  Destroy(Prefab);
  ObjectsList[id].AddComponent<StructureData>();
  ObjectsList[id].GetComponent<StructureData>().id = id;
  }

Until I used DestroyImmediate (without reading what it really gives), after that the script has already stopped displaying these prefabs, for some reason they are already null, although they are manifestly ...
why is this construction - because it is created according to the full code an empty prefab, then a few more, and then they become its children, well, when the prefab is added to the array, the original is deleted, otherwise there are 2 of them...
DestroyImmediate takes destruction out of the normal script execution order.

The question is what to do now?
How to get back to work now?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-10-01
@Zimaell

Because you are deleting the original prefab itself in the project, not its copy in the stage.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question