inheritance vs seperate script components

Hi All,
Ive a set of ai bots in my project, they all share the same basic movement functions. But on top of this they have type specific action functions (ie prey,predator etc). In C++ I would normally make a base bot class with the movement functions in and then inherit form this to make my other specialsied bots.

Now I understand I can do this in unity but ive been reading that it might be better to do it through 2 seperate script components and interfacing. Im not sure how to do this.

I might need my inherited object to update variables of the base class (if it was inherited that would be fine) does this mean i have to keep ap pointer to the other base script compenent all the time and reference it that way? If so then thats fine, but it just seems like another level of ‘pointerness’ that unity already seems full of…Im not sure it would make any difference to performance once compiled, but it seems a lot less seamless than standard inheritance.

Whats the best approach…?

thanks

It comes down to preference, but if it’s all for the same purpose (AI movement and actions) I’d say using inheritance would be advisable.

Although in C# you could define an interface that defines your AI. Similar to a pure virtual class in C++, it is the only way to implement from multiple types in C#. That would allow you to define types and categories easily that can have different updates and checks.

I’m of the opinion that a single behaviour should be a single script, and interfacing should be between sets of functionalities, as opposed to having one functionality be defined on a single object via multiple scripts. Inheritance will probably be faster, however it will probably be minor.

Thanks ntero, since im used to C++ i think i’ll go for inheritance, Im used to it and the fucntion calls wil be all nice and seamless etc