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 ChazAshley1 · Oct 23, 2015 at 10:38 AM · buildunity 4.6resources.load

Why Resources.Load does not works in Build?

Hello there. I just trying to load different types of resources using Resources.Load method. In Editor it works fine but when I make some build (windows standalone or iOS) - Resources.Load every time returns Null and I just cant load any resource. Why it so? How to fix it? Here is more info. I wrote a code which shows me if the resource was downloaded or not.

 BGArt = (Sprite)Resources.Load(app.model.pathTrialImages+BackgroundArt, typeof(Sprite));
 
         if (i < 5)
         {
             if (!BGArt)
                 Debug.LogError(app.model.pathTrialImages + BackgroundArt + " \t value: " + BGArt);
 
             var bga = Resources.Load(app.model.pathTrialImages + BackgroundArt, typeof(Sprite));
             Debug.LogError("---var---: " + app.model.pathTrialImages + BackgroundArt + "\t value: " + bga);
 
             i++;
         }

And here is Debug.Log in Editor alt text all right... But in builded EXE.. alt text

As you can see, in build assets just don't uploads

About TextAsset - early I could not download it, but this code fixed it.

 TextAsset ta = (TextAsset)Resources.Load("data", typeof(TextAsset)); 
         string data = ta.text;

But with rest of assets it did not help.

About different types of Resources.Load - I just try all (or not all?) types of that method. See code below

BGArt = (Sprite)Resources.Load(app.model.pathTrialImages+BackgroundArt, typeof(Sprite));

     if (i < 10)
     {
         Debug.LogError("-----I: " + i + "----- START");
         Debug.LogError("Type name = (Type)Resources.Load(path, Type)\t value: " + BGArt);

         var bga = Resources.Load(app.model.pathTrialImages + BackgroundArt, typeof(Sprite));
         Debug.LogError("var name = Resources.Load("+ app.model.pathTrialImages + BackgroundArt + ", Type) \t value: " + bga);

         var bga1 = Resources.Load<Sprite>(app.model.pathTrialImages + BackgroundArt);
         Debug.LogError("var name = Resources.Load<Type>("+ app.model.pathTrialImages + BackgroundArt + ") \t value: " + bga1);

         Sprite bga2 = Resources.Load<Sprite>(app.model.pathTrialImages + BackgroundArt);
         Debug.LogError("Type name = Resources.Load<Type>(" + app.model.pathTrialImages + BackgroundArt + ") \t value: " + bga2);

         Sprite bga3 = Resources.Load<Sprite>(app.model.pathTrialImages + BackgroundArt+".jpg");
         Debug.LogError("Type name = Resources.Load<Type>(" + app.model.pathTrialImages + BackgroundArt + ".jpg" + ") \t value: " + bga3);

         Debug.LogError("-----I: " + i + "----- END\n");
         i++;
     }

So I'm trying to download batch of sprites, and for first 10 of them I do Debug.Log(). Here is log for first three sprites

 -----I: 0----- START
 Type name = (Type)Resources.Load(path, Type)     value: 
 var name = Resources.Load(images/iphone/iphone_6/game/trial/pg1pt01, Type)      value: 
 var name = Resources.Load<Type>(images/iphone/iphone_6/game/trial/pg1pt01)      value: 
 Type name = Resources.Load<Type>(images/iphone/iphone_6/game/trial/pg1pt01)      value: 
 Type name = Resources.Load<Type>(images/iphone/iphone_6/game/trial/pg1pt01.jpg)      value: 
 -----I: 0----- END
 
 -----I: 1----- START
 Type name = (Type)Resources.Load(path, Type)     value: 
 var name = Resources.Load(images/iphone/iphone_6/game/trial/pg2pt01, Type)      value: 
 var name = Resources.Load<Type>(images/iphone/iphone_6/game/trial/pg2pt01)      value: 
 Type name = Resources.Load<Type>(images/iphone/iphone_6/game/trial/pg2pt01)      value: 
 Type name = Resources.Load<Type>(images/iphone/iphone_6/game/trial/pg2pt01.jpg)      value: 
 -----I: 1----- END
 
 -----I: 2----- START
 Type name = (Type)Resources.Load(path, Type)     value: 
 var name = Resources.Load(images/iphone/iphone_6/game/trial/previous kept, Type)      value: 
 var name = Resources.Load<Type>(images/iphone/iphone_6/game/trial/previous kept)      value: 
 Type name = Resources.Load<Type>(images/iphone/iphone_6/game/trial/previous kept)      value: 
 Type name = Resources.Load<Type>(images/iphone/iphone_6/game/trial/previous kept.jpg)      value: 
 -----I: 2----- END


All Resources,Load() returns Null.

ss-2015-10-22-at-045117.png (26.7 kB)
ss-2015-10-22-at-045428.png (46.8 kB)
Comment
Add comment · Show 11
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 Dave-Carlile · Oct 21, 2015 at 06:05 PM 0
Share

Going to need more information. How about some sample code? And show how the resource appears in the project hierarchy.

avatar image ChazAshley1 Dave-Carlile · Oct 21, 2015 at 06:11 PM 0
Share

I have Resources folder in Assets folder. In Resources folder I have "data.txt" file, but I see only the name - "data". Code looks simple TextAsset textAsset = Resources.Load("data") as TextAsset; //also I have try TextAsset textAsset = Resources.Load("daya");

All that code works fine in Editor, but not in builded app.

avatar image Statement · Oct 22, 2015 at 06:21 PM 0
Share

Does the build log give you any clues?

avatar image ChazAshley1 Statement · Oct 22, 2015 at 06:33 PM 0
Share

nope, it does not =(

avatar image Statement ChazAshley1 · Oct 22, 2015 at 06:48 PM 1
Share

Can you make a new project that just has a Resources/data.txt and a script to load it and see if that works? If it doesn't, upload your small project somewhere so we can see it.

You could also put the txt file in Strea$$anonymous$$gAssets and load it with System.IO.File.

Show more comments
avatar image Dave-Carlile · Oct 22, 2015 at 06:46 PM 0
Share

What if you use the generics form of the function...

 Sprite sprite = Resources.Load<Sprite>("your/sprite/path");

Also this...

 var bga = Resources.Load(...

The best the compiler can tell about the data type for bga is that it's a Object, which is the data type returned by the function. Either declare the variable using the data type, or again use the generics version. Not sure why it would behave differently in different environments... regardless, I always prefer explicitly declaring the variable type when it's ambiguous like this. So this...

 var bga = Resources.Load<Sprite>("your/sprite/path");

will make sure the compiler knows bga is a Sprite and not just an Object. I don't know if that will make any difference in what you're seeing though, but I don't really see anything else that's odd.

And you said something about a Text asset?? I don't see anything like that in your code.

avatar image Jessespike · Oct 22, 2015 at 06:46 PM 0
Share

have you tried including the file extension? Try "data.txt" ins$$anonymous$$d of just "data". You can also try different overloads that .Load provides, Dave mentions this in more detail.

avatar image Dave-Carlile · Oct 22, 2015 at 08:22 PM 0
Share

In your updated code, you're always logging bga, not bga1, bga2, etc..

Also, if the variable were actually null, wouldn't you be getting a null reference exception on your log messages ins$$anonymous$$d of an empty string?

By default, logging the way you are is going to use the ToString() method, which for Object returns the object's name property. I suppose it's possible that property is an empty string? Try logging .name directly ins$$anonymous$$d. or bga.GetType() or something.

avatar image ChazAshley1 Dave-Carlile · Oct 22, 2015 at 08:24 PM 0
Share

O$$anonymous$$G! Going to fix it xD

avatar image Dave-Carlile ChazAshley1 · Oct 22, 2015 at 08:26 PM 1
Share

I do that sort of thing regularly :D

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ChazAshley1 · Oct 23, 2015 at 02:56 PM

I have fixed it already. The problem was in folder with sprites.

I have had next folder hierarchy:

  1. Assets
    1. Resources
      1. images
        1. ipad

        2. iphone

Ipad and Iphone folders just contain the same sprites but with different size. And when I have deleted Ipad folder all works fine.

Why? I dont know.

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

33 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

Related Questions

Files put inside a Resources folder still don't end up in the build 1 Answer

why the Apk file size is too larger after build........? 2 Answers

Arguement Out Of Range (ONLY IN BUILD) 1 Answer

Why is hard drive space being used when creating an iOS project onto an external drive? 1 Answer

How to fix editor freezing after code change? (during build) 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