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
1
Question by moosefetcher · Nov 13, 2015 at 11:01 AM · c#texturesresources.load

How to load (and display) a texture png from my Resources folder

I've been following various pieces of advice but nothing has seemed to solve this problem. I'd like to set up a sequence of planets, each based on a Planet prefab. I've got the planets instantiating and I can customize their size and so on, but I need to specify which surface textures (atmosphere, etc) each will use.

I've been using...

 _textures.Add(Resources.Load("/Textures/img_surface1.png" ) as Texture);
 Debug.Log("_textures[0] = "+_textures[0]);

...where _textures is a List, but _textures[0] is logged as nothing (it doesn't say 'null', the console logs only "_textures[0] = ").

Later, to add the texture to the planet, I do....

 GetComponent<Renderer>().material.SetTexture("_MainTex", _textures[0]);

..but the planets just display all white.

I'd like to know what I'm doing wrong. If it's because I'm loading a png, what's the alternative? I've tried using a jpg. Am I supposed to be loading an actual Unity Texture type? If so, how would I get one external to Unity to begin with? I've tried all manner of URLs; with the slash, without; with 'Resources' at the start, without; both with a slash and without.

My Resources folder is in the Assets folder of my project and it has a Textures folder where the img_surface1.png image (amongst others) lives.

Is there anything obviously wrong with what I'm doing?

Any help appreciated. Cheers.

Comment
Add comment · Show 1
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:55 AM 0
Share

@moosefetcher hey Do you have any idea what is wrong with my code: Renderer rend = GetComponent();

Texture textureFace = Resources.Load("face2") as Texture;

rend.material.mainTexture = textureFace;

the game isn't responding to this

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by fffMalzbier · Nov 13, 2015 at 11:04 AM

A friendly quote from the documentation

The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted.

http://docs.unity3d.com/ScriptReference/Resources.Load.html

Change the path from

"/Textures/img_surface1.png"

to

"/Textures/img_surface1"

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 moosefetcher · Nov 13, 2015 at 04:21 PM 0
Share

Thanks for your answer. I should have said I also tried it without the file extension. The Instantiated planets were still displayed white. I'm pretty sure it must be the loading that's not working though(Surely Logging _texture[0] would show something, right?). No clue what's wrong. If there's anything else about my code that looks wrong, please let me know.

avatar image
2

Answer by el_kloklo · Jan 06, 2017 at 09:54 AM

I had the same problem, and found solution in older question, you should not have the root "slash" and, no extension. Change the path from "/Textures/img_surface1.png" -> "Textures/img_surface1"

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 saschandroid · Nov 13, 2015 at 11:04 AM

From unity script reference: "The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted." So: no ".png" at the and :)

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 moosefetcher · Nov 13, 2015 at 04:45 PM 0
Share

Hi there. Thanks for the answer. I should have said that I had tried it without the extension too. Is there anything else the code needs to be doing? Does the texture load instantaneously or do I need to listen for a 'loaded' event maybe? Really not sure what's up. If you have any ideas, I'd be keen to hear them.

avatar image
0

Answer by TouxStudio · Mar 15, 2019 at 11:31 PM

Hi all, exists some way to avoid write exter al permission to load a png img from Resources?

Greetens

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

8 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

What is the difference between Resources.Load("url") and Resources.Load("url") as type ? 3 Answers

Algorithm for loading sounds 1 Answer

(C#) change texture and shadow resolution 0 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