I’m having an issue with a prefab that gets used all over my project. When I enter a specific scene, the prefab itself gets deactivated and cannot be activated again without exiting play mode, re-enabling the prefab, and restarting play mode.
Is there anything that can deactivate the prefab from a scripting or animation perspective? Those are the only things I can think of that might be causing this. Note that I mean the prefab reference loaded from the assets folder, not the instantiated GameObject. I don’t have any code snippets because I really don’t know where the code that causes this is.
This seems like somewhere in your code you are disabling the actual prefab, instead of a prefab instance reference.
Try checking your code for that.
Try adding the following code to any of the scripts enabled in your prefab, then look for the logs and observe the stack trace to try to find out where the disable is being called from:
private void OnDisable()
{
Debug.Log("Object was disabled here");
}
Thanks for the reply, this was really helpful. I did end up fixing my issue using this method.
It turned out that in one of my classes I had this snippet:
public CustomObject Object;
public Button ButtonObject{
get { return Object.Prefab.ButtonScript; }
private set{}
}
instead of this:
public CustomObject Object;
public Button ButtonObject{
get { return Object.Instantiation.ButtonScript; }
private set{}
}
At some point, ButtonObject.SetActive(false)
was called, disabling the prefab.
2 Likes