Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by angryFlo · Dec 05, 2013 at 03:24 PM · texturesresources

Load 2D Textures with Resource.Load doesn't work

Hi,

i want to change a texture of an mesh if something happend in my script. I use the following code for loading a jpg. das 2D Texture but it doesn't happen.

 Texture2D oil_fund;
 
 void Start () 
 {
 oil_fund = (Texture2D)Resources.Load("Resources/oil_splash.jpg");
 }
 
 ...
 
 renderer.material.mainTexture = oil_fund;
 

Do You have an idea why my .jpg isn't loaded ? The picture is located at Assets/Resources/oil_splash.jpg

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Lovrenc · Dec 05, 2013 at 03:27 PM

My guess: Since the function is "Resources.Load" i doubt that you have to type in "Resources/oil_splash.jpg" since it is already looking in resources folder. Also, image types (.jpg, .gif, .jpeg) are to be ignored. Try

 Resources.Load("oil_splash");

Ignore this answer if you have Resources folder inside your Resources folder :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image angryFlo · Dec 05, 2013 at 04:19 PM 0
Share

It's the same, doesn't work either :-(

avatar image
2

Answer by GameVortex · Dec 06, 2013 at 10:51 AM

Try setting the type you want:

 oil_fund = Resources.Load("oil_splash", typeof(Texture2D)) as Texture2D;

If it does not work then double check your spelling of the file and the Resources folder. It has to be exact. It is case sensitive as well. So the Resources folder needs an upper case 'R'.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image angryFlo · Dec 06, 2013 at 12:41 PM 0
Share

Thanks but problem still exists... nothing happend again. only the attached texture via inspector disappears.

avatar image GameVortex · Dec 06, 2013 at 12:56 PM 0
Share

Well, there is not much more to it than this to load from Resources.

Is your oil_splash.jpg imported as a texture or sprite or something else?

Last thing would be to zip up your project and attach it here and I could take a look at it if you want.

avatar image angryFlo · Aug 12, 2014 at 07:33 PM 0
Share

Finaly late but not to late, the error was a misspelled filename in the script... sorry my fault. all answers are working then.

avatar image anorman149 · Jan 16, 2016 at 03:26 AM 0
Share

This was a great find. I had Resources.Load("Prefabs/units/Player") as Player and it wasn't working. As soon as I added typeof(Player), it worked.

avatar image
0

Answer by JDDesigner · Jun 03, 2017 at 11:56 AM

Also make sure, that you do not enclude the filetype. So DON'T do this:

 oil_fund = (Texture2D)Resources.Load("Resources/oil_splash.jpg");

But do this instead:

 oil_fund = (Texture2D)Resources.Load("Resources/oil_splash");

I am not an expert and only started coding in C# a few moths ago, but when I was having this problem removing the filetype helped.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by DanialKM · Sep 09, 2019 at 02:33 PM

try this I promise this would work { string address = Application.dataPath + "your local address"; or {string adress = "Resources/oil_splash.jpg"} byte[] byteArray = File.ReadAllBytes(@address); Texture2D pic = new Texture2D(12080,1024); bool check = pic.LoadImage(byteArray); if(check) print("done"); } i had same problem and finally i read bytes and then pass it to Texture2D ,try this I promise this would work { string address = Application.dataPath + "your local address"; or {string adress = "Resources/oil_splash.jpg"} byte[] byteArray = File.ReadAllBytes(@address); Texture2D pic = new Texture2D(12080,1024); bool check = pic.LoadImage(byteArray); if(check) print("done"); } i had same problem and finally i read bytes and then pass it to Texture2D
,try this I promise this would work { string address = Application.dataPath + "your local address"; or {string adress = "Resources/oil_splash.jpg"} byte[] byteArray = File.ReadAllBytes(@address); Texture2D pic = new Texture2D(12080,1024); bool check = pic.LoadImage(byteArray); if(check) print("done"); } i had same problem and finally i read bytes and then pass it to Texture2D

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does loading a Resource load that resource's dependencies? 1 Answer

Textures of different resolutions 1 Answer

Assigning a texture for object in inspector. Is it loaded right away? 0 Answers

Pink texture with Resources.Load 0 Answers

How can I load textures, sounds, and prefabs from users hard disk? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges