Best way to Resources.LoadAll GameObjects in folder to array C#
I am currently having trouble trying to load all my "block" references to instantiate from a "Blocks" folder inside the "Assets/Resources" folder. I can put them into an array, but instantiating from that array won't work (not an instance error) and I feel this is due to how I am using LoadAll method. I have been wandering around the internet for answers, but every answer is different or brings an error. The only working piece I have even gotten is just :
blocks = Resources.LoadAll("Blocks") as GameObject[];
(blocks being predefined , and having this in Start() )
Answer by ThatGuyMiniB · Jul 13, 2017 at 09:36 PM
Idk if this is still relevant but this is what worked for me.
using System.Linq;
void Awake()
{
blocks = Resources.LoadAll("Blocks").Cast<GameObject>().ToArray();
}
Blockquote Idk if this is still relevant but this is what worked for me.
using System.Linq;
void Awake()
{
blocks = Resources.LoadAll("Blocks").Cast<GameObject>().ToArray();
}
Blockquote
That worked for me, thank you ThatGuyMiniB
Your answer
Follow this Question
Related Questions
Cant define array from other script 0 Answers
Checking if an instance of a Script saved in 3d array is null 1 Answer
Best way to serialize a big array of a class 2 Answers
Get Vector3s in range 1 Answer