I personally use a coding structure that I call “Static Inheritance”, as all class references are static, and each class is inherited from the Main(which I call Slave.cs).
public class Slave : MonoBehaviour
{
public static List<Animals> allDogs = new List<Animals>();
public static List<Animals> allCats = new List<Animals>();
// etc...
}
So then, you can easily create a function within Slave.cs, especially with Object Pooling, to reference or even iterate through the particular List you need. Which I’ve benchmarked to be way more performant when sorting calls and references.
The problem you mention, is a problem I once had when perfecting said code structure. The parent class, unless placed in an object in the scene, will not “perform” any code on it’s own. Which I found, through many hardships along the way, is a very good thing. Because in all intents and purposes, you don’t want the parent class to read during runtime, only each child which is meant to be running within the scene.
So, ergo, the parent class doesn’t need an Awake(), Start(), or even Update(). The parent class only needs to contain variables(public) that each child class would use, that can be called in a generalized function that would be called from elsewhere. Or as you’ll find when playing around with Inheritance, the parent also can contain functions that either said child would use, or not use(which is main argument on why some say Inheritance is bad).
Now I do notice, that in your example, you show class01 > class02 > class03. Which is fine as long as class01 and class02 do not contain structured voids(Awake, Start, etc…), then using structured voids within class03 is perfectly fine. However, if you need a particular(parent) class to have it’s own Awake()? The best way I found was something like this:
private void Awake()
{
if ([classReference] == null && this.name == "[className]")
{
[classReference] = this;
DontDestroyOnLoad([classReference].gameObject);
}
}
To which I only needed in one of my projects. For the most part, each structured parent class is to only group and define certain classes, or allow certain functions to be called in each group. I will show an example:
public class Animals : Slave
{
public bool action;
public void Bark()
{ playSound(Bark001.wmv); }
public void Meow()
{ playSound(Meow007.wmv); }
}
public class Cat : Animals
{
void Awake() { allCats.Add(this); }
void Update()
{
if (action)
{ Meow(); action = false; }
}
}
public class Dog : Animals
{
void Awake() { allDogs.Add(this); }
void Update()
{
if (action)
{ Bark(); action = false; }
}
}
There are many more ways to use Inheritance properly, and ways that solve many issues with other forms of code structure, but I feel like I’ve typed enough for now, lol. I hope anything I’ve said helps someone in the future, or better yet gave them a spark for a new idea! Cheers!