What is the best way to avoid or reduce the amount of monobehaviours in your scripts?

Hiya devs,

Basically as the question states. What is the best way to avoid or reduce monobehaviours in your game? I have a 3D endless runner, well, flyer, where everything is object pooled to save on constant instantiation. Although, I am finding I have a lot of scripts for the game, and each has a Monobehviour inheriting.

I have recently started to learn about Scriptable objects, but unsure how these can help me in my game.

Thank you for any answers. :slight_smile: Have a great Sunday too.

I also had this question recently, because I’m still pretty new to gamedeving.

One way I’m currently trying out is to have 1 main monobehaviour, “Monogame”, in an empty gameobject I call “Core”. I then let my Monogame initiate and call my own update methods in all my static scripts. These static scripts are not Monobehaviour, just “plain” C# classes.

This means that most of my core game code is actually not Monobehaviour, but various static “managers”. Doing this, I found that I didn’t have to rely on MonoBehaviours for everything any longer. Any Monbehaviours I have on gameobjects now are mostly to capture collisions, but I’m sure they are useful for a lot more if used correctly.

My monogame might look something like this (simplified):

public class Monogame: Monobehaviour{

	void Start(){
		// Prepare references and variables as necessary
		PlayerCharacter.Init();
		AIHandler.Init();
		MapHandler.Init();
	}

	// Update is called once per frame
	void Update () {
		// Input to movement for the players character
		PlayerCharacter.Update();

		// Move entities
		AIHandler.Update();

		// Load new maps
		MapHandler.Update();
	}
}