Override Actor Component functions in Owning Actor?

The desired result here is to create a modular weapon system, and avoid a hugely bloated weapon actor class and improve flexibility.

You would have a shell actor that is the “Weapon” class. The actor acts as a convenient container for components. The idea is that the “Weapon” can specify a number of modules, and then the Weapon blueprint determines how those modules interact with each other. The actor weapon doesn’t care what each componetn does, it just acts as a central place for modules to talk to each other in a scriptable fashion.

Here’s an example:

A weapon actor has a “Shoot Projectile” component, which contains common C++ code for firing a projectile. Before it can fire a projectile, it calls it’s own function “CanFire()” - which is tagged as a BlueprintNativeEvent. The important part here is that the function is contained in the component so logic is compartmentalized, and so that the weapon ‘Actor’ does not become bloated with functions that any possible module would need to call.

So lets say I also have an ‘Ammo’ module added to that weapon actor. The ‘Shoot’ module has a BlueprintAssignable event called “OnShotFired”, which in stock UE4 I can add directly into the actors event graph, and tell the ‘Ammo’ module to remove some ammo. Just like this:

What I Can’t do right now however, is override the ‘Shoot’ modules ‘CanFire()’ function directly in the Actors event graph, to ask the ‘Ammo’ module if it has enough ammo. The idea is that end users can add any number of modules they like to a ‘Weapon’ blueprint, and the ‘Weapon BP’ then defines how those modules behave with each other.

This way, I don’t have to create module blueprints for every weapon, and the weapon actor doesn’t need to know about all the possible functionality of every possible module.


If you can think of another way to achieve this I’m all ears - but right now it feels like allowing the actor to create a blueprint implementation of it’s components’ functions is the only way to do this, but I’m not sure.

I’m about to just give up and create the CanFire() etc. functions in the Weapon Actor class, and modules will have to call the respective functions from the actor and pass themselves along, e.g. CanFire(UHT_FireModule* CallingModule)

1 Like