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 /
  • Help Room /
avatar image
0
Question by jgtoastie · Jul 17, 2017 at 04:39 AM · spriteimageresourcesui imageresources.load

Resource.Load always returning null when trying to load an image

Hi all,

I've scoured the forums but I'm really unsure what's going wrong here - from what I can see, I'm following everything to the letter.

I'm making an application that that requires images to be dynamically brought in on startup, but I'm hitting a stumbling block where I'm unable to even bring in an image from the Resources folder at all.

I'm trying to load an image into a UI image in a canvas. I've assigned a placeholder so that I can easily see if it changes:

alt text

This image is then referenced in a parent controller GameObject and dragged in through the inspector. Here's the code in the controller that should load the image. I've bypassed a lot of code that makes it dynamic and am just trying to directly reference pork.jpg which is in the project resources folder.

 public Image image;
 
 ...
 
     void updateImage(string filename) {
 
         //filename = filename.Substring(1, filename.Length - 2);
         Sprite sprite = Resources.Load<Sprite> ("pork") as Sprite;
         image.GetComponent<Image>().sprite = sprite;
         if (sprite == null) {
             Debug.Log ("Pork is null!");
         }
         //Debug.Log ("yay!" + Application.dataPath + "/Resources/img/" + filename);
     }

Unfortunately, despite the fact that my sample image is in the root of the Resources folder (that's projectname/Assets/Resources), it just keeps returning null:

alt text

Again, I'm finding it difficult to see where I'm going wrong. I've tried countless combinations of the code, largely informed by responses to similar topics on this forum, but I'm still unable to get Resources.Load to actually load a sprite. This also happens with whatever sample image I try, regardless of file extension, and there are no error messages or anything.

Can anyone please give some recommendations? Ideally I want to be able to use Resources.Load so I can load in all the images at once and save on calls, but I haven't been able to get that far yet since I can't get it to work in the first place.

Thanks very much.

load1.jpg (44.1 kB)
load3.jpg (232.8 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jgtoastie · Jul 25, 2017 at 09:15 AM

For the record, I ended up using the solution here: https://forum.unity3d.com/threads/generating-sprites-dynamically-from-png-or-jpeg-files-in-c.343735/ to bring images dynamically, since I couldn't find any other way to convert an image brought into the Resources folder to a sprite after the project had been republished.

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

136 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 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

Loading a new sprite into an image array 0 Answers

Changing UI Image's sprite, preserve aspect ratio is checked but not working? 0 Answers

Show screen capture as UI image 1 Answer

How to load resources? 1 Answer

Referring to sliced sprites in Resources by name 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