Resource.load gives inconsistent results
I have some strange behavior that I don't understand at all. When I open my project and run my app my resource is not loading (getting the message "NullReferenceException: Object reference not set to an instance of an object") . I make a simple change in the script (add a blank line), go back to unity, wait for the script to compile, and the app runs just fine giving the results I expect. I save the project and exit out of unity - get back into Unity, load and run the project and I get the same error again. Can delete a blank line from the script and the app runs fine again.
Any suggestions / help would be appreciated. (The null exception happens at the Debug.Log line)
Thank you.
void Start () {
CreateSystemSlots(InventorySlots, "Inventory", SlotsAmount);
}
public void CreateSystemSlots (GameObject systemSlots, string type, int amount) {
var theManager = GameObject.Find("InventorySystem").GetComponent<InventoryManager>();
GameObject slot1 = new GameObject();
slot1 = Resources.Load<GameObject>("Prefabs/Slot");
Debug.Log("Slot 1 is null " + slot1.Equals(null));
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613030416im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
problem with asset 2 Answers
I seriously cannot learn how to script. What do I do? 4 Answers
Why when i color 4 walls of a grid 10x10 it's coloring 10,9,9,8 and not 10,10,10,10 ? 0 Answers
How could i save a variable called by multiple objects using the same script? 1 Answer
Can jump even when in the air. 0 Answers