Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
0
Question by hexagonius · Aug 10, 2015 at 11:44 AM · gameobjectinputcomponentsysteminputmanager

How to mimic Unity's Components based System

Hey everyone,

I'd like an insight or opinion about how to implement a good component based system.

Example: Whenever a GameObject gets a Rigidbody Component attached, the transform gets automagically altered when running the game due to PhysX. From what I understand is that Unity checks all GameObjects for their components and plugs them into it systems.

Now my question is how I would go about doing the same thing with custom components?

Let's say I create a component that makes a GameObject touchable (adds a boxcollider2D too). I don't want every GameObject to run an overlapPoint on itself to see if it was touched. I'd rather run that once and the object found accordingly, let's call that class InputManager. This already means I have to write a component and a system that works it.

How do you guys setup the necessary system? does every component register itself to the InputManager, where that instantiates itself on the first call (singleton)? Or do I keep an InputManager System on a GameObject in the scene which searches the whole scene in the beginning? Or just check the touched GameObject if there's the corresponding component available and call stuff on it? Do I need to do that for every component, write an outside system? I mean, this is how Unity works, right?

Comment
Add comment · Show 4
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 Owen-Reynolds · Aug 10, 2015 at 02:46 PM 0
Share

It might help if you could explain how this is about using Unity3D. Right now, the question is more about how not to use Unity.

I would assume one of the reasons Unity wants us to use AddComponent (ins$$anonymous$$d of just a new) is because it does register every Component with the proper handler, at Start/creation.

avatar image hexagonius · Aug 10, 2015 at 03:20 PM 0
Share

Every component Unity provides works right out of the box. Add a Rigidbody, Object falls down. Add a Collider, Object collides. Everything just by adding that. I would like to design a component, if added, that makes the GameObject selectable. But not by querying the Input-Class in its Update function. That would basically mean every GameObject would do that. Ins$$anonymous$$d there should be an InputSystem which checks the Input once and works with those Components. Just like PhysX works with Rigidbody Components. I don't know how to explain this any better. $$anonymous$$y guess is that NOT the Rigidbody component itself is doing calculations but PhysX is, and on GameObjects with one such component. Therefore I'd also like to create such a System, that operates on Components. But I don't know what the best way is to get those together properly.

avatar image Owen-Reynolds · Aug 10, 2015 at 04:06 PM 0
Share

I think what you're asking is clear enough. What isn't clear is how it relates to you making a game using Unity. In general, we purposely don't care how Unity does most things, unless they have quirks that can affect the game.

avatar image hexagonius · Aug 10, 2015 at 07:02 PM 0
Share

Could you explain this further, I think I don't get it. Who is we (Devs or Users) and how is not caring about how things work a bad idea? I just want to adapt to good practices and patterns and try to understand how Unity uses them.

Another example would be a health component. Adding that to a GameObject would give it the possibility of losing or receiving a certain amount of a total amount of health. But HOW would then dying be implemented? Health doesn't know about any animator or what GameObject it is the health of (Boss, Ship, Player?)

There must be some greater "$$anonymous$$d" interpreting and handling that ("if health == 0, kill the guy by doing that and that and that). So again, there's the component, but something else ("System?") must be running the show, which needs to know about all "Health" Components to handle them properly

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Youri1er · Aug 10, 2015 at 12:53 PM

Singleton is good especially if you want to keep data between scene. Make legacy to make vector of mother. And then you can use it to call update of all children. If a component requires other , test if the component is null.

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

26 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

Related Questions

Write custom input manager 0 Answers

How to get different Animations when different button combos are pressed 2 Answers

Activate objects/crafting in a game. 1 Answer

Component Array 0 Answers

Mapping multiple controllers 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