Unity Composition and Inheritance

July 29, 2019

Unity Composition

Composition vs Inheritance

Youtube – Unity Architecture – Composition or Inheritance?

By: Unity3d College

I was looking to use inheritance with an overall parent abstract class to create a few simple scripts, but was having some trouble getting it setup properly. When looking into how to approach this better, I came across the concept of “Composition vs Inheritance”. This is the first time I heard the word composition, but it appeared to be the idea in Unity of creating a bunch of small scripts that perform specific types of functions that can be placed on objects in a varied structure style to create the proper type of object you want.

I thought this was a neat concept that made a lot of sense in Unity, so I ended up using this idea to approach the issue I was working on. This got me into using RequireComponent(typeof) in Unity, which I’d seen before but never really used. This seemed to be a nice feature to keep track of with a composition style approach since there will probably be a lot of cases where certain components will need others to be there, and this is just a good practice to make sure you don’t have any issues when setting up your structured object.