Accessing Child Events/Functions From Child Class/Actor

Hi,

I have been working on a combat system and weapon equipping

I have a Parent class called BP_Weapon from this I have derived Child Classes of BP_Sword and BP_Bow, of which functions/events are available on the child class BP_Bow which I would like to access

These Weapons are presented in the way of a Data Table where eventually they will be cascaded down to have different types of sword and bow (wood, metal etc)

Entries in the Data Table are derived from the struct BPS_Weapons below where the Weapon Class is of the Parent Class BP_Weapons, which I can then reference the Child class in the Data table.

In my combat system that references the above data table, I have 2 functions, EquipBow and EquipSword.

Equip Bow

Equip Sword

Passing the Child Class through the structure into spawn actor from class does give me a child actor of that class however, I have to cast on both functions in order to access the child functions/events inside BP_Bow and when doing so the blueprint is working as expected

Is this a standard way to approach this? and for the eventual addition of the child classes of BP_Bow (BP_WoodenBow etc) will additional casts need to be incorporated to access any functions/events in the lower classes if any? or should care be taken to include them all in BP_Bow so that they are inherited and if not needed do not use them?

Hey @Gardx! Welcome to the forums!

You’re on a good track here with one exception:
It needs to be flipped around.

I’m assuming you’re putting all of this on the player character, as you never stated where this was but that what it seems like.

Once an actor is spawned, you can have that actor talk BACK to the player as part of its begin play. You can have that actor tell the spawner (in this case, the player) what abilities and variables the spawned actor has, using “Get Owner” if you pass in “Self” as owner on “SpawnActor”.

Otherwise, you will end up with the player actor getting bloated, storing all of the information, which is what you’re trying to avoid by using a DataAsset.

Hope that helps!

Hi @Mind-Brain thank you for the information.

It is not on the player character but inside an actor component that sits on the player character called BPC_CombatSystem. I made it an actor component so it could be used potentially on AI enemies in the future without the need to redo functionality.

When you say flipped around I’m not quite sure what you mean? Do you mind clarifying? I’m not really wanting the player to know about the Bow and Sword, just the combat system itself. The combat system knowing more about the Bow, sword and weapon classes.

I think what I’m wondering or trying to answer/understand is why in my equip sword and equip bow functions above (on the actor component) I have to cast to the BP_Bow or BP_Sword Actor when I have spawned the actor and have a reference of the passed in actor out of the spawn actor node? Why can I not store it as a variable with BP_Bow Object reference or BP_Sword object reference and then access the functions that way? Is it because it is just a reference to an actor and not a actual actor? if that makes sense? If I print the return node it would say BP_Bow0 / BP_Sword0