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 /
avatar image
0
Question by naghekyan · May 17, 2016 at 01:48 PM · scripting problemgameobjectcomponent

How to handle coupled components in Unity

The idea on ECS architecture is that you have components that are pure data, that are being added to the Entities that are pure collection of Components and then you have systems that depending on the containing component types of each entity either process the entity or not eventually completing some functionality. The benefit is that when you add or remove a component (which is just data), you change the behavior of the Entity.

In Unity things are in different way. You have predefined components for which some functionality is written in the engine. You can also define Scripts which contain data AND behavior. What if that behavior requires data farm multiple Components/Scripts? [In pure ECS it is always like that - several components constitute a single functionality. (e.g. PositionComponent and MoveComponent together result the Entity to move and if one of them is absent, Entity will not move).] I mean I can randomly add and remove components and Scripts, and still each Script in my Game Object should know if it has all the components required to accomplish the functionality. How should I achieve this in Unity?

P.S. I need this so that if I would remove a component/script some functionality will be disable util I add it back.

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
0

Answer by meat5000 · May 17, 2016 at 01:53 PM

I found your question a little unclear but I think you are looking for this

http://docs.unity3d.com/ScriptReference/RequireComponent.html

Which will automatically add a required component if flagged in a script.

I dont believe there is one for removing. Its easy enough to Destroy(Component) in your script though.

You probably know that scripts are often linked with GetComponent.

Unity doesnt identify with one Pattern, although it is Object and Component Based. You are pretty much free to mix your patterns as you require them. I'd say Unity is a little different from the Computer Science "Stick to the book" way of doing things.

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

Answer by YoungDeveloper · May 17, 2016 at 01:55 PM

Why not just execute code on awake and ondestroy?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

"There is no 'GameObject' attached to the "x" game object' 2 Answers

Is there a way to dynamically attach a script to a GameObject during runtime? 1 Answer

How to add components to other GameObjects through a C# script attached to one? 2 Answers

Can't disable component, little checkbox is missing from inspector 1 Answer

Access water4 scripts via my script? 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