null reference on instantiated prefab array at instantiation
So I had this script that makes an instance of a prefab, and uses it for somethings. Well I realised that I need to be able to handle all of my instanced prefabs so I made it an array. sadly i keep getting an error.NullReferenceException: Object reference not set to an instance of an object (wrapper stelemref) object:stelemref (object,intptr,object) AddDevice.Connect () (at Assets/Scripts/AddDevice.cs:86)
Which leads to this line of code
panel[arrayFilled] = (GameObject)Instantiate(Resources.Load("DevicePanel"));
Which makes no sense, since that's the line where I create the instance?
panel and arrayFilled are intialised globally as follows:
private GameObject[] panel; private int arrayFilled;
And arrayFilled is intialised to 0 in Start();
Answer by JedBeryll · Apr 25, 2018 at 12:45 PM
Filling an array does not give null reference error so it can only be that the file is not where you specified or the name of the file is misspelled. Resources.Load requires a "Resources" folder based path. Meaning that if you have the object at Assets/Resources/Prefabs/DevicePanel then the correct way to load is Resources.Load("Prefabs/DevicePanel");
Your answer
Follow this Question
Related Questions
[Quiz Game] How to prevent Question asked twice. HELP 1 Answer
Move enemy to a specific movepoint with an array (C#) 1 Answer
How to reference UI Panels, in an array for x and y? 0 Answers
How to remove scenes from a list of random scenes upon completion? 0 Answers
Need help with 3d inventory system 0 Answers