Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
4
Question by Nerdmigo · Sep 17, 2012 at 01:50 PM · prefabsresourcesfolders

Correct Folder for Resources.Load() ?

hi guys, i am pretty new to unity, and i cant see through the folder structure that is nessecary for a call of Recources.Load("MyPrefab") to not return null but give me a proper instance of a game object (i know that i need to typecast beforehand). The script reference says:

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

So does it mean the "Standard Assets" Folder ? (i am using the free version) I am quite confused... if somebody could give me a hint i would be glad. thx in advance.

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
8
Best Answer

Answer by whydoidoit · Sep 17, 2012 at 02:23 PM

Assets is the root folder of your project (you don't see it in Unity - it is the owner of everything in the project view).

You can create a Resources folder anywhere and the path for Resources.Load is the path beneath that.

Resources/My Folder

    Resources.Load("My Folder/SomeResource")
Comment
Add comment · Show 13 · 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 Nerdmigo · Sep 17, 2012 at 02:35 PM 0
Share

i just figured it out that moment, thats exactly what i did wrong ! thx ! While we are at that topic do you have a suggestion how i should structure the content of my Assets folder ? At the moment i have $$anonymous$$yProject/Assets/Audio.. and then something like Fonts, Scripts, and so on... but now i realize that i probably need : $$anonymous$$yProject/Assets/Resources.. as well, for anything that i need to load inside the script right ? so basically all my prefabs need to go there...

avatar image whydoidoit · Sep 17, 2012 at 02:40 PM 1
Share

Your prefabs need to go there if you want to load them at runtime yes - though there are other techniques like having an game object with a script containing all of the prefabs you want - it depends on your design style. Basically anything that isn't in a Resources folder isn't going to make it into the build unless it is referenced in one of the built scenes.

You can have that resources folder anywhere and you can have more than one:

  • Images/Resources/$$anonymous$$y Folder

  • Fonts/Resources/$$anonymous$$y Folder

Both of which are accessed in the same way as in my answer (they are kind of compiled together).

I try to keep my projects organised with a root Resources folder because I like to be able to find them all when I need them (to remove something I don't need to reduce the build size normally).

avatar image tkamruzzaman whydoidoit · Nov 22, 2015 at 02:03 PM 0
Share

works fine. Thanks :)

avatar image Nerdmigo · Sep 17, 2012 at 03:19 PM 0
Share

so basically, if i put assets into a scene (e.g i add an audiofile to a gameobject in the scene) then i am good, but if i want to create objects at runtime i need to put them into a resources folder... i think i got that ! The thing with the gameobject, i didnt get that, do mean i should place one gameobject created from the prefab into the scene beforehand? thx in any case, great clarification !

avatar image whydoidoit · Sep 17, 2012 at 03:23 PM 0
Share

Right well imagine you have a prefab holder script that has a variable for every prefab you want to create. You set this up in the scene then just access it through the variables:

UsefulPrefabs.js

    static var current : UsefulPrefabs;
 
    var spaceShip : GameObject;
    var bullet : GameObject;
    var enemy : GameObject;
    var weapons : GameObject[];     


    function Awake() {
         current = this;
    }


The you can drop one of those into the scene and use code like:

    var myNewWeapon = Instantiate(UsefulPrefabs.current.weapons[1]);


  

    
avatar image whydoidoit · Sep 17, 2012 at 03:24 PM 0
Share

You just need a reference to the prefab to create it at runtime - so it either needs to be loaded with Resources.Load or by in a variable on something in the scene.

Show more comments

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

13 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

Related Questions

Prefab cant istiantiate through recources.load? 1 Answer

Resources.LoadAll on Current Folder Only? 1 Answer

Controlling prefabs from Resources Folder 1 Answer

About to gut my use of the Resources folder. What are the best practices going forward? 1 Answer

Nested prefab in Addressable prefab 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