• 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 kholera · Apr 02, 2015 at 12:29 PM · texturenullreferenceexceptionload

Resources.LoadAll returning null but everything seems right

I am attempting to use a script to create an animated fire texture. I have the textures downloaded, and they are stored in a folder "Unity Project/Assets/Resources/25 frames" which contains a number of images.

I have written the following code in my script. It is designed to load all of these images into an array of textures, and then have an update function change the texture displayed constantly (to create sensation of animation).

 using UnityEngine;
 using System.Collections;
 
 public class fireTextureCycle : MonoBehaviour {
 
     Texture[] fireFrames;
     int framesPerSecond = 10;
 
     // Use this for initialization
     void Start () {
         //load fire textures
         fireFrames = Resources.LoadAll ("25 frames", typeof(Texture)) as Texture[];//("Textures/FireLoop1/PNG Frames/256x256/13 frames", typeof(Texture)) as Texture[];
 
         if (fireFrames == null) { 
             Debug.Log ("Load failed.");
         }
     }
     
     // Update is called once per frame
     void Update () {
         int index = (int)(Time.time * framesPerSecond) % fireFrames.Length;
         gameObject.renderer.material.mainTexture = fireFrames [index];
     }
 }

As far as I can tell, this code should be correct. I have looked up the Unity documentation on LoadAll, and it seems to indicate that I have used it properly here. Despite this, I find that LoadAll always returns null. This is confirmed by my Debug.Log statement "Load Failed" which triggers every time. I have also seen some other questions on Unity Answers regarding this same issue, but the answers which I saw did not help me with my problem. Can anyone explain why I am having my issue?

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 ppolonio · Dec 02, 2015 at 06:43 PM

Consider re-writing line 12 as either "fireFrames = Resources.LoadAll("25 Frames");" or "fireFrames = Resources.LoadAll("25 Frames", typeof(Texture));" (possibly appending "as Texture" to the latter). I believe the fault in your code might be the cast, as you might be trying to cast a texture as an array of textures, which will fail and return null. LoadAll would sooner return an empty array than a null, I think.

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 saschandroid · Dec 03, 2015 at 08:22 AM 0
Share

Documentation:

 fireFrames = (Texture2D[]) Resources.LoadAll("25 Frames");

Btw: a possible error could be using white spaces

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Resources.Load(path+name) as texture == null reference 7 Answers

Crash on Texture Select 2 Answers

Save Multiple GameObject with XML 1 Answer

Skybox showing mostly white 0 Answers

Android Problem with load 32MB texture 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