- Home /
Resources.Load With Scriptable Objects
I am trying to load a list of scriptable objects from the resources folder. For whatever reason, Resources.loadAll does not find anything in the resources folder.
Here is my code ...
Object[] ideas = Resources.LoadAll("Assets/Resources/Ideas/", typeof(Idea));
print(ideas.Length); //prints 0
Here is a screenshot of my resources folder and what is in it...
Thank you for the help!
Try Object[] ideas = Resources.LoadAll("Ideas/", typeof(Idea));
ins$$anonymous$$d. Whenever you are trying to load something within Resources folder, you don't have to type in Assets/Resources.
Answer by Carter0 · Jan 03, 2020 at 01:10 AM
Yeah I tried that and it still does not find anything in the folder.
Any other ideas (Haha)?
You can try this which removed / after Ideas. I think you don't really need the forward slash there. : Object[] ideas = Resources.LoadAll("Ideas", typeof(Idea));
If that doesn't work, you can also try this but this will try to load everything within that folder. : Object[] ideas = Resources.LoadAll("Ideas");
Yeah, that made some progress. Now it finds something in the right folder with
Object[] ideas = Resources.LoadAll("Ideas");
But now I need to cast that to the Idea Scriptable Object class. Do you have any ideas on how to do that?
This worked out for me. Tested it out on my system.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class TestFindIdeas : $$anonymous$$onoBehaviour
{
public List<Idea> Ideas = new List<Idea>();
void Start()
{
Ideas = Resources.LoadAll<Idea>("Idea").ToList();
}
}
You don't really have to use List like I used in my example though. I prefer using List over Array due to its flexibility.
Your answer
