Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Resources.LoadAll

static function LoadAll(path: string): Object[];
static Object[] LoadAll(string path);
static def LoadAll(path as string) as Object[]
static function LoadAll(path: string, systemTypeInstance: Type): Object[];
static Object[] LoadAll(string path, Type systemTypeInstance);
static def LoadAll(path as string, systemTypeInstance as Type) as Object[]

Parameters

pathPathname of the target folder.
systemTypeInstanceType filter for objects returned.

Description

Loads all assets in a folder or file at path in a Resources folder.

If path refers to a folder, all assets in the folder will be returned. If path refers to a file, only that asset will be returned. The path is relative to any Resources folder inside the Assets folder of your project.

Note:
All asset names & paths in Unity use forward slashes, paths using backslashes will not work.

	// Loads all assets in the "Resources/Textures" folder
	// Then picks a random one from the list.
	// Note: Random.Range in this case returns [low,high)
	// range, i.e. the high value is not inclusive.

function Start (){ var go = new GameObject.CreatePrimitive(PrimitiveType.Cube); var textures : Object[] = Resources.LoadAll("Textures"); var texture : Texture2D = textures[Random.Range(0, textures.Length)]; go.renderer.material.mainTexture = texture; }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Start() {
        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
        Object[] textures = Resources.LoadAll("Textures");
        Texture2D texture = textures[Random.Range(0, textures.Length)];
        go.renderer.material.mainTexture = texture;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Start() as void:
		go as GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube)
		textures as (Object) = Resources.LoadAll('Textures')
		texture as Texture2D = textures[Random.Range(0, textures.Length)]
		go.renderer.material.mainTexture = texture

static function LoadAll(path: string): T[];
static T[] LoadAll(string path);
static def LoadAll(path as string) as T[]

Parameters

pathPathname of the target folder.

Description

Loads all assets in a folder or file at path in a Resources folder.

If path refers to a folder, all assets in the folder will be returned. If path refers to a file, only that asset will be returned. Only objects of type T will be returned. The path is relative to any Resources folder inside the Assets folder of your project.

	// Loads all assets in the "Resources/Textures" folder
	// Then picks a random one from the list.
	// Note: Random.Range in this case returns [low,high)
	// range, i.e. the high value is not inclusive.

function Start (){ var go = new GameObject.CreatePrimitive(PrimitiveType.Cube); var textures = Resources.LoadAll.<Texture2D>("Textures"); var texture = textures[Random.Range(0, textures.Length)]; go.renderer.material.mainTexture = texture; }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Start() {
        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
        Texture2D[] textures = Resources.LoadAll<Texture2D>("Textures");
        Texture2D texture = textures[Random.Range(0, textures.Length)];
        go.renderer.material.mainTexture = texture;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Start() as void:
		go as GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube)
		textures as (Texture2D) = Resources.LoadAll[of Texture2D]('Textures')
		texture as Texture2D = textures[Random.Range(0, textures.Length)]
		go.renderer.material.mainTexture = texture