• 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 PezDeGoma · Aug 30, 2018 at 10:03 PM · prefabperformanceparentchild

All project as child of one gameObject is a good idea?

I was looking the different ways to get a prefab reference. And I want to know which is the best way for performance. I know 4 for the moment:

The first one is use gameObject.Find (I think this is the worst for performance).

The second one is to create a public GameObject and use the drag and drop in the inspector.

The third one is use the resources folder and call it directly but I read that is better to don't use this method too much.

And the last one is my last idea: Create a gameObject as a parent of all the elements in the scene and find each gameObject using GetChild().

Regards.

Comment
Add comment · Show 1
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 Sergio7888 · Aug 31, 2018 at 06:12 AM 0
Share

You can use a ScriptableObject to hold references of the prefabs.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by JVene · Aug 30, 2018 at 11:50 PM

The context of usage of the prefab really dictates the optimum method to use. If a prefab is used for bullets and casings on a weapon, you want quick access so you keep a reference handy at all times because the prefab is used throughout the game.


If the prefab is a fixture, say the typical example light pole, then you're using the prefab during initialization of the scene. If there's only 1, a find isn't going to be that heavy, and you'll re-use a reference for subsequent multiple instantiations (you definitely don't want to execute find inside a loop for each instantiation).


So, from your title, the notion of your last idea is confusing. Do you contemplate the entire project is a prefab? I don't know that I understand what that's getting at. Whatever means you use to find objects, the larger the number the slower the performance. Typically, if we are still talking about prefabs, you'll have some objects that are prefabs, then everything else that isn't. If you want the prefabs in the scene (and, really, what is a prefab but something you're going to duplicate), perhaps what you want to do is create an empty GameObject as a node that contains all the prefab options, so when you search the code only searches through prefab options and not all objects in the scene.


That said, there's no real obstacle to putting everything as a child of some uber parent if you have reason. I did that in one case during an experiment after importing a model of lots of meshes comprising the artwork for a scene that required scaling. I placed everything as a child of an empty GameObject, which let me scale everything in one step. It worked fine, but the volume 'low-medium' - about 8,000 facets overall, with some 500 objects inside.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

132 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

How can I prevent position of a child transform to be hooked to the parent in a prefab? 1 Answer

How to properly edit prefabs with child elements? 1 Answer

Instantiate a Prefab as child 0 Answers

Prefab, procedural attachment of child, childCount return 0 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