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
33
Question by _Petroz · Oct 23, 2010 at 10:04 PM · componentinheritancearchitecturebestpractices

Game architecture best practices

Is there any best practices guides, or just advice regarding the best approach to game architecture for Unity? In particular Unity's component system seems to allow a completely different approach than standard object oriented design.

For example, generally composition is favored over inheritance and the component system makes composition so easy that it seems that inheritance is redundant. I realize you have to inherit from internal Unity classes like MonoBehaviour but I'm referring to inheritance of user created classes.

Similarly polymorphic behaviour doesn't require an abstract base class, you can just replace 'component A' with 'component B' to get different behaviour.

I'm moving toward this way of thinking lately and it got me wondering if there are any guides or resources that outline how to approach architecture in Unity.

Comment
Add comment · Show 6
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 Hibame · Oct 25, 2010 at 01:38 AM 9
Share

Not quite an answer but some good reading can be had from: http://www.insomniacgames.com/assets/filesadynamiccomponentarchitectureforhighperformancegameplay.pdf http://cowboyprogram$$anonymous$$g.com/2007/01/05/evolve-your-heirachy http://stackoverflow.com/questions/1901251/component-based-game-engine-design/3495647#3495647

avatar image Brocccoli Hibame · Mar 21, 2016 at 08:49 PM 0
Share

I was first developing my game using almost strictly OO design methodologies until I stumbled across a few posts on Unity Answers describing Component Based design.

and GOD DA$$anonymous$$N is it SO $$anonymous$$UCH EASIER to implement in Unity. $$anonymous$$y productivity in my game has doubled and it is SO EASY to extend and add functionality to game objects.

I still have some objects that inherit from others, but those instances are more specific functionality of generalized components.

Anyone wondering whether or not they should adopt a component based design for their game, especially in Unity, DO IT!!! It will help you in the long run.

avatar image _Petroz · Oct 25, 2010 at 03:11 AM 0
Share

Those resources are fantastic, thanks! Communication between components is not something I had given much thought to, it seems that is the biggest challenge.

avatar image Fattie · Jun 12, 2012 at 07:37 AM 1
Share

Peter - just FWIW my observations match yours precisely. Purely FWIW I think you're probably right in that one should / one has to "go with the flow" of exactly the "architectural feel" you describe. Unity3D is meant to be, well, simple, the "particular flavour of OO suggested by the overall unity environment", just as you describe ... you just kind of have to go with it I think.

As petroz mentions "Communication between components" for example is completely obvious, natural and sloppy in Unity. I waste a lot of time being offended by architectural "feels" that don't match the previous system I had to work on a couple yrs ago.

"are any guides or resources that outline how to approach architecture in Unity" I think the actual answer is No. :) Unity is setup as a system for "civillian" programmers, I doubt that even 2,000 of the now one million Unity developers would even understand what the hell your post here is about, Peter!!!

avatar image Moix · Jul 27, 2013 at 03:11 AM 0
Share

$$anonymous$$y god, at last someone that understands me... I'm really struggling on how to "think" in Unity after doing OOP for years... did you ever find any useful info on those subjects related to Unity?

avatar image RyanZimmerman87 · Jul 27, 2013 at 08:09 AM 2
Share

Well I'm completely opposite in terms of program$$anonymous$$g background. I started up with Unity as soon as I programmed a text game in Visual Studio in C++ that had a simple leveling and item/store system, turn based combat.

But even I find the lack of information regarding these kind of topics for Unity extremely annoying. There is really no good resources which explain how any of it works, all they do is give you a one liner syntax example which usually results in a debug notification.

It's kind of a joke to be honest. I am so OCD that I would probably $$anonymous$$r my hair out if I was co$$anonymous$$g from a proper program$$anonymous$$g background and had to deal with their resources. Even co$$anonymous$$g to Unity as a complete beginner I constantly find myself wishing they had useful information.

Generally it seems like the way to go is just don't even think about it, figure it out through trial and error because none of these answers seem to exist for Unity. It's like the whole Game Engine is just a toolbox with tons of random crap for you to sort through but no instruction guide.

All that being said I am amazed with the progress I have made in developing my game with Unity in this short time, it's just not a fun process to try to master a program when you are alone in the woods with a pocket knife and a box of matches.

3 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by boymeetsrobot · Oct 26, 2010 at 07:51 AM

I have just started to use Unity and was looking for some resources on this myself.

There is an excellent video on the subject by Mike Mittelman of Hangout Industries from Unite 2008 that can be found on Unity3d.com http://unity3d.com/support/resources/unite-presentations/techniques-for-making-reusable-code

Also check out http://forum.unity3d.com/threads/37896-Programming-architectures (I am currently using the iPhone friendly NotificationCenter class by Prime31 and it works in a similar way to the Actionscript 3 event model).

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
3

Answer by BTables · Feb 01, 2014 at 06:13 PM

I found this thread a couple of months ago lacking a good answer, just found this page with more information I could ever dream of specific to unity:

50 Tips for working with unity - Best practices

Comment
Add comment · Show 1 · 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 sandygk · Feb 22, 2016 at 03:24 PM 0
Share

Apparently this is the only article on the whole web that touches on the subject in a comprehensive way. We should have more of this...

avatar image
2

Answer by spinnerbox · Feb 22, 2016 at 03:46 PM

Unity is a game engine and like probably all other premade engines on the market, it uses Component based software architecture. That means you see all parts of your game like components i.e I can put one component A into another component B which will give behavior A to the component B. For example I can add keyboard component to my component Player in order to make my Player move with keyboard buttons. As simple as that. If you were to use polymorphism and inheritance you could possible end up in inheritance mess, very hard to maintain. Engineers found that Component based structure is the best way to make a game engine.

I would recommend a rather old book on the OOD patterns which is kind of too broad but you will find Component pattern there as well: http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612

This is also a good intro to Component based software engineering

Edit: The biggest problem of component based architecture is that all that visual and bussines logic is mixed within a component aka MonoBehavior. And even if you try to separate visual from bussines logic you will again need to use inheritance which will end in a mess. So I would recommend, functionality that can stand alone or in separate C# class to be moved from a MonoBehavior. That way your code will stay clean and maintainable.

Comment
Add comment · Show 1 · 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 NextUpGames · Jun 29, 2017 at 07:55 AM 1
Share

Just to add a useful link for users like me; That are starting out, have some knowledge in program$$anonymous$$g, but missing the overall concept on how to dissect your game logic. I found the tutorials from Jesse Freeman very useful.

Since the question here is about Composition over Inheritance, maybe his video will help some of you. (Please note, that it's not free. Ofcourse you can subscribe for a trail) https://www.lynda.com/Unity-tutorials/Composition/540497/570507-4.html

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

15 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

Related Questions

Composition: Multiple actions on death 1 Answer

Ability System with Modular Targeting: having trouble finding a good way to map between input components and effect components 0 Answers

Class inheriting Runtime Classes 1 Answer

Callbacks in component based design 1 Answer

An OS design issue: File types associated with their appropriate programs 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