Components based programming

Published September 17, 2020
Advertisement

I have been looking at Data Driven Development with Unity, but so far I haven’t been able to understand how everything works in that aspect with the jobs, burst compiler etc. Maybe I will later, but for now I want to focus on what I know so that we can build this game and get it done.

What I did like about that approach is that it follows Unity’s convention of using components.
So in stead of creating a script called “Player.cs” which handles Input, movement, health etc. I have separated each area into a separate component.

We have a “Moveable.cs” component script which will handle all kinds of movement.
This can be attached to a player, or any NPC/Enemy object, or even inanimate objects that need to move.
Anything that needs to move gets the “Moveable” component.

Then we have a “Killable.cs” component, which handles health, damage, healing etc.
Anything that can be killed will have a Killable component.
We even use UnityEvent in the Killable script so that the Game designer can decide what happens when the entity dies.
If we want to play a dying animation, the entity must also have the “Animate.cs” component we made, so that the Game Designer can choose to set certain values in the animator controller using the Killable script.
Everything becomes very modular, easy to maintain and flexible.

Using this approach lets us build characters without having to re-write or reuse any script code.
If we want to change how entities move in the game, we simply change the “Moveable” script and we’re done.

One thing I haven’t taken into consideration is possible optimization issues, but for the scope of our game, I don’t think performance will be an issue.

1 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement
Advertisement