NewPersona
NewPersona

Reputation: 1731

Calling Resources.Load on a texture is not working

I'm trying to load a Texture from the Resources folder but it keeps on returning null.

t = (Texture)Resources.Load("Circle") as Texture;

The circle texture has an extension of .tga.

Upvotes: 2

Views: 10350

Answers (4)

Pokémon master
Pokémon master

Reputation: 11

@Massimiliano Uguccioni thanks... that fixed my problem.

Steps to use Resources.load:

  1. make sure its in the Resources folder
  2. reference full relative path without Resources: eg: textures/texture1 where textures is a folder inside Resources
  3. like Massimiliano Uguccioni said dont include file extension

Upvotes: 1

Hemant Singh Rathore
Hemant Singh Rathore

Reputation: 2139

Single Texture File

Texture File should be added into Resources folder After that use below lines of code for load texture

var Texture_1 : Texture2D;
Texture_1 = Resources.Load("TextureName");

For Folder

Folder should be in kept into Resources folder After that use below lines of code for load folder of textures

var textures : Object[];
textures = Resources.LoadAll("FolderName");

Upvotes: 2

Massimiliano Uguccioni
Massimiliano Uguccioni

Reputation: 151

The extension of the file isn't necessary. So this is correct:

t = (Texture)Resources.Load("Circle") as Texture;

This is not:

t = (Texture)Resources.Load("Circle.npg") as Texture;

Upvotes: 2

Igor
Igor

Reputation: 373

You must put Circle.tga in Assets/Resources folder. Plus if you have subfolder, for example Resources/Textures/Circle.tga then do like this:

Texture t = Resources.Load("Textures/Circle") as Texture;

Upvotes: 2

Related Questions