Multiple inheritance ?

Hi,

After some weeks spent in the Editor, this is my first post here.

I’m extending a sample project, Third Person, and I built and “Enemy” base BluePrint. It handles health, damage, HUD for healthbar of the enemy, and so on.

Today, I’d like to create an EnemyCharacter_BP which will behave like all others Enemies, but is based from CharacterBP (so it has character movement, animation, …). Please not that some enemies (most of them ?) that are not based off Character. (Some of them will even be static meshes that the player need to destroy).

So, here is my problem : if I create the “EnemyCharacterBP” based on Character, it doesn’t have my “health system”. If I create it based on my EnemyBP, it isn’t a character.

I’d like to find something like C++ mixins or PHP traits, but using Blueprints. I tried to use an ActorComponent but it look like, inside it, I can’t access variables from the main Actor. Let’s say I need something like an Interface but with embedding the actual implementation in all of my blueprints (instead of rewriting it).

Any lead would be greatly appreciated !

(Note: If it’s something possible in C++ but not in Blueprints, I can take the leap.)

2 Likes

Multiple inheritance is not even possible in UE4 C++. Each class can only have 1 parent.
So you will most likely rework your setup to fit this.

What you could do is creating Components for your different systems. For example the Health System can be a component.
Then you can add it to every Class you want, without having to worry about parent classes.

You can also just create a child class of your Enemy thingy and add the MovementComponent to it (so create your own Character Class).

OR you split character and Enemy classes and work with Blueprint Interfaces. There you can define functions that you can implement differently on all
classes and just call it on the simple actor reference instead of needing to cast first. (I know you said you need something slightly different like that, but
maybe it’s still an option if you change your setup)

So i would try out the Component + BPI way.

3 Likes

Ok, thank you for this explanation.

So, I’ll try to use Components. The thing I don’t like about Interfaces is that I have to “copy/paste” code when two classes share the same behavior. Anyway, I’ll make some trial and error based on your reply.

Thanks again !

eXi, my man, love your stuff on YouTube, twitch steam on networking helped.

On my game instance, I want to run a thread.

class MOVAZONE_API UcustomGameInstance : public UGameInstance, public FRunnable
{
GENERATED_BODY()

public:

virtual bool Init()
virtual uint32 Run();
virtual void Stop();

but game instance has a method called init already, how can I bypass this: ?

1 Like