Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by Grey_Wolf9 · Jul 25, 2018 at 09:10 AM · textureresources.loadfolder

Loading texture from Resources folder not working

Hello all

So I want to load different textures for my game object when different conditions are met. Below is a snippet of one of the conditions: if ((amount > 151f) && (amount < 200f)) { Material.color = Color.blue; Renderer rend = GetComponent(); rend.material.mainTexture = Resources.Load("face2") as Texture;

             }

This does not work and I do not understand why. Please assist; I am so frustrated with this right now

Comment
Add comment · Show 5
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 Piyush_Pandey · Jul 25, 2018 at 09:19 AM 0
Share

If you exactly copy pasted your code, then i think you made the mistake while using Renderer rend = GetComponent(); .As it gives a compiler error, i think you did not do that. So i think the problem is with loading of the texture itself. Just give a try to :-

 Renderer rend = GetComponent<Renderer>(); 
 
 Texture textureFace = Resources.Load("face2") as Texture;
 
 rend.material.mainTexture = textureFace;


Now use debugger to check if the texture is loaded correctly. $$anonymous$$any times its the case of wrong path/name while loading from the resources

avatar image Grey_Wolf9 Piyush_Pandey · Jul 25, 2018 at 09:24 AM 0
Share

Hey Piyush

Thanks for your reply.

i put the code you sent into my code and it still doesn't work; not sure why

avatar image Grey_Wolf9 Piyush_Pandey · Jul 25, 2018 at 09:28 AM 0
Share

Also I am a Unity beginner and not really sure how to use the debugger.

avatar image Shemamforash · Jul 25, 2018 at 11:45 AM 0
Share

If you get any error messages, could you post them here?

avatar image Grey_Wolf9 Shemamforash · Jul 26, 2018 at 12:35 AM 0
Share

Sure, I will post them here if any should come up. Nothing has come up as yet; still do not know what's wrong with this

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by madks13 · Jul 25, 2018 at 09:34 AM

Resources.Load looks at resources in the Resources folder. If your resource is in a subfolder, you should add the relative path. For example, if your face2 is located at Resources/charcaters/faces/face2, you should use Resources.Load("characters/faces/face2").

Comment
Add comment · Show 17 · 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 Grey_Wolf9 · Jul 25, 2018 at 09:40 AM 0
Share

@madks13 Thank you for your reply.

I just checked again to make sure and there are no subfolders in the resources folder Not sure why this code isn't working

avatar image madks13 Grey_Wolf9 · Jul 25, 2018 at 09:41 AM 0
Share

what is the face2 resource you are trying to load?

avatar image Grey_Wolf9 madks13 · Jul 25, 2018 at 09:45 AM 0
Share

Its a jpeg file, just a small picture I want to change the pictures on a sphere as each condition is met

Show more comments
avatar image
0

Answer by Grey_Wolf9 · Jul 28, 2018 at 06:02 AM

This seems to work:

  if ((amount > 151f) && (amount < 200f))
                 {
                 Renderer _rend = GetComponent<Renderer>();
                 Material _mat = _rend.material;
                 _rend.material.mainTexture = Resources.Load("face2") as Texture;
                 _mat.color = Color.blue;
                     
             }
Comment
Add comment · Show 3 · 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 madks13 · Jul 30, 2018 at 09:02 AM 0
Share

Sorry, this was my mistake. After you posted the code, i understood what was wrong, which also was pretty obvious : you were simply setting the color before setting the texture. So each time you were basically setting the texture with default color. You should select this as the answer in case someone else has a similar problem so they can see the solution easier.

avatar image Grey_Wolf9 madks13 · Jul 30, 2018 at 09:08 AM 0
Share

Accepted the answer.

Thanks for your help

avatar image madks13 Grey_Wolf9 · Jul 30, 2018 at 09:12 AM 0
Share

No problem. As i mentioned in point 3 : Even expert programmers make mistakes. The more experience and knowledge one has in program$$anonymous$$g, the easier it is to overlook the simplest errors, because of their obviousness. Thus the importance of debugging :)

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

116 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with missing texture with Instantiate( Resources.load ) method 0 Answers

Resources.Load Problem 1 Answer

Does reference to Texture count on RAM usage of device? 0 Answers

Can't add texture to procedurally generated plane 1 Answer

Can't find texture file path using Resources.Load() 1 Answer


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