- Home /
Resources.LoadAll Failing When Not Generic Object Class
I have some editor scripts where I am loading all assets at a path. So I am running this code not during play mode.
The following code works:
public void LoadAllCards()
{
Object[] assets = Resources.LoadAll("ScriptableObjects/Cards", typeof(Object)) as Object[];
Debug.Log(assets);
foreach (Object card in assets)
{
Debug.Log(card);
}
}
The following code does NOT work. assets is NULL always in this case. M_Card is just a ScriptableObject.
public void LoadAllCards()
{
cards = new List<M_Card>();
M_Card[] assets = Resources.LoadAll("ScriptableObjects/Cards", typeof(M_Card)) as M_Card[];
Debug.Log(assets);
foreach (M_Card card in assets)
{
Debug.Log(card);
}
}
Do you know why Resources.LoadAll is working just fine if I use generic objects (and when I later cast it to M_Card, it works just fine), but is not working when I specify a specific class (like ScriptableObject or M_Card)?
Answer by Goa · Mar 23, 2016 at 01:59 PM
Try:
M_Card[] assets = Resources.LoadAll<M_Card>("ScriptableObjects/Cards");
Your answer
![](https://koobas.hobune.stream/wayback/20220611232025im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can i use the Instancing in max to Place/Replace/Instantiate in Unity 3 Answers
Can you use a more performant undo function than RegisterSceneUndo with DestroyImmediate? 2 Answers
How can you access scripts in a folder called "Editor" from elsewhere? 2 Answers
How can I delete the Main Camera using a script? 1 Answer
System.UnauthorizedAccessException to Temp dll.mdb when running project 0 Answers