Last Updated on 2021-10-31 by Clay
In the past, I always used Resources.LoadAll<Sprite>()
to create an Array<Sprite>
object, but today, when trying to optimize the program, I tried to change to Resources.Load<Sprite>()
to read a specific Sprite.
But since changing to this way of reading, the Sprite I read is cannot display any pictures; In other words, I use Resources.Load<Sprite>()
return Null
.
To confirm whether the Null
is returned, just print it out.
Solution
Refer to the stackoverflow discussion at the bottom link, there are two solutions.
Method 1: Make sure that the path you put in the Resources folder is correct and that it is Sprite.
The folder name cannot be wrong at all. It should be noted that the Unity engine will not only look for the Resources folder under Assets, but also look for other folders to see if the Resources folder is included.
Method 2: Make sure you did not enter the file extension
For example, the picture name you originally entered is:
mySprite.png
It needs to be changed to:
mySprite
References
Read More
- [Solved] adb: failed to install xxx.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.DefaultCompany.com.unity.template.mobile2D signatures do not match previously installed version; ignoring!]
- [Solved][Unity] Use “trigger” to Trigger but Rigidbody Does Not Simulate Collision
- [Solved] Visual Studio Cannot Auto Complete Unity Module and Function Name
Pingback: Resources Load Sprite | Using Resources To Get Assets In Code! [2] 14829 명이 이 답변을 좋아했습니다
Pingback: Unity Resources Load | Don'T Be Scared Of The Resources Folder!! [Unity Tutorial] 20710 좋은 평가 이 답변