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
1
Question by noanoa · Apr 26, 2014 at 05:11 AM · prefabresourcesinstantiate prefabresources.load

Eliminating prefabs from resources folder?

I really don't like that you have to place prefabs in resources folder to instantiate from scripts. It makes the project folder structure a mess and lots of scrolling and searching for certain prefabs.

I want to place prefabs in where I want to. Is there any easy workaround to achive this? Something that might work might be to make an empty scene and place prefabs and store their references to some static class's variables so later you can get the prefab from the static class. But it sounds awkward. Can anyone give me a better idea?

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

Answer by musaranya · Apr 26, 2014 at 06:18 AM

If you keep your assets folder well organized with subfolders it shouldn't be a problem to have all your resources there including the prefabs. I'm not sure you are doing it right but I think the cleanest way to instantiate prefabs is as follows:

  • in the script from where the prefabs will be instantiated place a public variable of a type that can points to the prefab (a component included in the prefab, usually a Rigidbody, an AudioClip, etc)

  • then in the inspector panel you should see this as a property of the object which has this script attached: drag your prefab from the well organized project panel to this slot, it should match if the prefab contains a component of the type set when declaring the public variable in the script

  • and that's all, then in the script code you can instantiate this kind of prefabs without having to have them scattered around (remember that you need to make a cast within the instantiation if you're in C#)

hope it helps

Comment
Add comment · Show 2 · 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 MikeNewall · Apr 26, 2014 at 07:20 AM 0
Share

To add to that you can have multiple resource folders throughout your project so rather than having all resources that you're loading by code jumbled in one folder you can create a bit more structure.

avatar image noanoa · Apr 27, 2014 at 03:42 AM 0
Share

Thanks, had to google and re-read your answer a lot to figure out what you are saying but I think I got it o.o I didn't know you could instantiate a prefab by refering components.

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

22 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

Related Questions

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

What does Unity actually do when Loading Resources that already exist? 0 Answers

Referencing prefab in code without using editor or Resources.Load? 0 Answers

Resources not loading in APK 0 Answers

Resources.Load() What has to be in Resources Folder 1 Answer


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