0
votes

I have a number of png files which I am importing using C# (in Unity 5.3.5) and setting them to the sprite of an image. However, for only some of these files, Resources.Load gives me 'null' when this code is executed.

Resources.Load<Sprite>(@"Instruction_Files/1");

As a specific example, the first image I will upload (7.png) gives me the Sprite when I call

Resources.Load<Sprite>(@"Instruction_Files/7");

In contrast, the second image I will upload (10.png) gives me null when I call

Resources.Load<Sprite>(@"Instruction_Files/10");

Renaming 10.png to 7.png, etc. and vice versa doesn't change things (the original 10.png will be null and the original 7.png won't be).

7.png 10.png

Is there a specific format that Sprite files need to be (e.g. square, a certain number of kB) for Resources.Load to work? Any potential method to solve this issue? Thanks.

UPDATE: Importantly, if I copy all the information in the 7.png.meta file and paste it in the 10.png.meta file, then 10 is registered as a sprite

1
Can you resize your image?Khalid Hussain
Couldyou paste some debug log? or error messages?Cabrra
There are no error/debug messages that occur naturally. When I do Debug.Log(Resources.Load<Sprite>(@"Instruction_Files/10")) I get 'null' for 10.png or Sprite(....) for 7.png.Jack Walsh

1 Answers

2
votes

The import settings need to be set on Sprite/UI like here (see the sprite/UI section). These are also the settings that are saved in the meta file.

Thats why it doesn't load when you rename the file in Unity from "10" to "7", because the meta file is also renamed and the import data is preserved. But when you copy the data from the meta you are actually changing the import settings.