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
1
Question by Scej · Nov 06, 2015 at 05:53 PM · gameobjectscriptingbasicsorganization

Empty gameobject just to hold scripts?

Would it be a bad practice to create an empty game object for the sole purpose of holding lots of generic scripts?

If it's ok, Is there anything to consider when doing this?

Examples scripts that the gameobject would hold.

  • All UI interaction and animation

  • Global timer

  • Scene loading

  • Character controller

  • Events

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

2 Replies

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

Answer by rutter · Nov 06, 2015 at 05:56 PM

Would it be a bad practice to create an empty game object for the sole purpose of holding lots of generic scripts?

Not at all. That sounds like a great idea to me!

Out of the scripts you mentioned, I'd usually rather attach a character controller to the character it's controlling. Other than that, though, all of those things could reasonably be global, either to a scene or in some cases even across multiple scenes.

For truly global objects such as game controllers and the like, you might consider singleton patterns that can automatically initialize the controller the first time it is referenced.

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 Scej · Nov 06, 2015 at 06:02 PM 0
Share

Thanks for the reply.

I'm new to unity dev, so to get an understanding of "whats bad" and "whats good".

How bad would it be performance wise to have the empty gameobject described above with ~200 scripts attached and each script contain an Update()?

I read somewhere that limiting the number of scripts containing Update() is a good practice.

avatar image rutter Scej · Nov 06, 2015 at 07:11 PM 1
Share

Welcome!

That question is getting more subjective, I think.

If I attached 200 scripts to one object, I'd be inclined to combine some of those scripts and/or break that into multiple GameObjects -- if nothing else, 200 components in the inspector is going to be overwhel$$anonymous$$g for designers.

Unity does come with a built-in profiler so you can check how much CPU time your scripts are using. I've had scenes with thousands of scripts running, so it really depends on what they're all doing. The more stuff you have going on in the scene, the more you may need to optimize for performance. General advice is to avoid worrying about that until it becomes a problem.

avatar image
0

Answer by tanoshimi · Nov 06, 2015 at 06:09 PM

It's generally good practice (not just in Unity) to place all code logic as close as possible to the thing to which it relates. So character controllers should be on characters, enemy AI should be on enemies etc. If you have generic global game controllers, make a generic game controller object (I.e. The empty Gameobject you describe) and attach them to that. It's perfectly good, and very common practice.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Get Audio Source On Another Object 1 Answer

How can I click on another object in script ? 1 Answer

Unity Addressable for player skins 0 Answers

How can I get gameObject from hirerchy to the public GameObject slot of a script attached to a prefab? 0 Answers

Disable and enable emission property of a material via C# script? 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