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
2
Question by BDX777 · Apr 13, 2016 at 11:06 PM · stringresources.loadfilesystemfilepathlimitation

Resources.Load without a Resources folder?

Is there any way to use Resources.Load with a file path from the root assets directory rather than a folder called Resources? Should I just put everything in a folder called Resources? I mean I could do just that, but would that cause any problems if I put everything except the Editor and Standard Assets folder in one big Resources folder?

Comment
Add comment · Show 2
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 AlucardJay · Apr 14, 2016 at 01:36 AM 0
Share

It is just good housekeeping to have anything that may be required in the build that may be loaded at runtime to be in a Resources folder.

http://docs.unity3d.com/$$anonymous$$anual/LoadingResourcesatRuntime.html : "Resource Folders are collections of assets that are included in the built Unity player, but are not necessarily linked to any GameObject in the Inspector."

Personally, all assets should be in a folder, any folder; not just random objects/textures/scripts dumped in the root assets folder.

"Should I just put everything in a folder called Resources?" : no. Everything in a resources folder will be included in the build, even if you never use it (attached to a gameobject in the inspector or possibly required at runtime). Again, it all comes down to how you manage your project window.

The answer to your question is Application.dataPath. This points to the assets folder in the editor, and the _Data folder in the build : http://docs.unity3d.com/ScriptReference/Application-dataPath.html

But you are going to have a really bad time if you do that, having to copy and paste those things into the data folder of your build. That's if it will even work, because you will then have to use WWW, and some asset types will just not be able to be loaded : http://docs.unity3d.com/ScriptReference/WWW.html

In short, organize your project window. Put everything in a folder (named scripts/textures/materials/models/prefabs/sound/whatever). Anything that is not attached in a scene but may be required to be loaded at runtime, put in a Resources folder.

$$anonymous$$ore experienced users will be able to explain how something that is instantiated doesn't necessarily need to be in a Resources folder, and how Resources.Load helps with the memory footprint of a build when running. Personally the only thing I put in a resources folder is something that will be network instantiated.

avatar image AlucardJay · Apr 14, 2016 at 02:18 AM 0
Share

Let's see if I can explain it better...

If you have something that is not in a scene, but will definitely be used in the game, then store a reference to it in a script, then call on that reference (can be in any folder):

 public GameObject myBarrel;
 // ...
 Instantiate( myBarrel, pos, rot );

If you have something that only might be required, then use Resources.Load, and it needs to be in a Resources folder:

 Texture superEpicPlayerSkinDLC = Resources.Load( "SuperEpicPlayerSkinDLC" ) as Texture;

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by Immanuel-Scholz · Apr 14, 2016 at 12:05 PM

During the player, there is no function to read assets directly from outside a Resources/ folder. Its not even possible, because if the asset is never linked and is not inside a Resources/ folder, it is completely removed from the build.

Within the Editor, just use AssetDatabase.LoadAssetAtPath()

You can move as much as you like into a Resources/ folder. You can also have subfolders within Resources/ folder and you can have a Resources/ folder within a subfolder.

Example:

 Assets/Resources/basics.bytes
 Assets/art/Resources/Sprites/mysprite.tga
 Assets/code/Resources/sample.prefab

You can load these objects like this:

 byte[] basics = Resources.Load<TextAsset>("basics").bytes;
 Sprite mysprite = Resources.Load<Sprite>("Sprites/mysprite");
 GameObject samplePrefab = Resources.Load<GameObject>("sample");


Two things to remember here:

  1. You need to specify the sub-folder when loading via Resources.Load

  2. Everything that is inside a Resources folder will be added to the final build, so be sure to remove all test assets and garbage before shipping to reduce game build size. (That is also true for all "test-GameObject's" that you leave in any scene that is shipped. Even if the GameObject is deactivated, all assets it references will be included in the build).

There is another option of dynamic resource loading: AssetBundles. Basically, you can pack any asset into an AssetBundle (from any folder) and later in the game load that bundle and then load things out of the AssetBundle in a similar syntax to Resources.Load.

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

42 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

Related Questions

Won't read files from directory on android - Windows works fine. 0 Answers

Store the path with Resources.Load in a string 3 Answers

Resources.Load returns null,Resources.Load don't load sprite 1 Answer

How to deal with discrepancy in application file path between running the exe vs running from Unity? 0 Answers

Using Unity UI Button to call .unity file 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