M
M
Max Bogachov2017-08-05 08:21:29
2D
Max Bogachov, 2017-08-05 08:21:29

Why is the sprite not being loaded by the Resources.Load method?

The question is this - I have a sprite, I declared it as hero2, and in void Start I assigned it a picture from the folder

Sprite hero1;
Sprite hero2;
void Start () {
    hero1 = sr.sprite;
    hero2 = Resources.Load<Sprite> ("back.png");
  }

But in the game mode in the inspector I chose debugging and in the script I see that hero2 has None, what should I do?1031448e78a84dd79e9fb011a535ed31.pngc87c7f55d7b14c329c3dee914c83ecbc.pngdf9f949181d94ce4bc477d1b6b05d6dc.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Silin, 2017-08-05
@Geekinder

Read at least a little documentation...
The sprite should be in the "Resources" folder, i.e. the full path to it should be "Assets/Resources/back.png" then it will load.

D
Daniil Basmanov, 2017-08-05
@BasmanovDaniil

First, make sure the sprite is in the resources folder, Resources.Load loads the relative path from all folders in the project called Resources. Secondly, when loading from resources, you do not need to specify the extension. Thirdly, there is a possibility that you are loading by the wrong name, back is the name of the texture, the sprite can be called back_0 or something, check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question