- Home /
Problem is not reproducible or outdated
Resources.LoadAllOfType With ScriptableObjects?
I am trying to add every ScriptableObject i find to a list. The ScriptableObject is called "Items"
EDIT: I already declared itemsList
Here's my code:
public void loadAllItemsInList() {
itemsList = null;
foreach (Items item in Resources.FindObjectsOfTypeAll(typeof(Items)) as Items[]) {
itemsList.Add(item);
Debug.Log (item.itemName);
}
}
It seems like it should work. But it doesn't. It just returns an error showing me where i declared my Foreach. And. Saying "Object reference not set to an instance of an object". No clue how to fix this
Answer by tanoshimi · Feb 13, 2017 at 11:54 PM
itemsList is null. I'm guessing you meant it to be a new List<Items>()
.
Follow this Question
Related Questions
Loading a ScriptableObject at Runtime. 1 Answer
Serializing a collection of ScriptableObjects to an ASSET file? 1 Answer
Resources.Load is not working with an existing file in Resources? 2 Answers
Unity Custom Inspector - Resources.LoadAll() returns 0 element. 1 Answer
Unity recompilation time slowly increases each time it's recompiled. Why? 0 Answers