Setting an actor reference to a specific actor reference


I have a question. I am trying to implement a button that calls a different ability based on what faction the current pawn is.

The way I set this is up is having an “update” event when the current pawn changes, and setting a variable “Ability 1” with type “Actor” to be variable “X Ability 1” with type “X Ability 1 BP” or variable “Y Ability 1” with type “Y Ability 1 BP”.

Then, on the button I am doing an “OnClick event” which should call the BP which is stored in the variable “Ability 1”.

This is where I have problems, what would be the best way to do that?

I’ve printed out what the variable “Ability 1” contains when i click the button, and it contains the correct ability reference for the current pawn.

hard to understand what you want to do. you want to change the variable type from actor to x ability or y ability type?

Yeah, it’s a bit hard to explain.

I want to call an event in ability blueprint “X” or ability blueprint “Y” based on which of the blueprints is stored in variable “Ability 1” (in button blueprint).

In other words, the question is how to call a blueprint (function, event, whatever) based on a dynamic/changing blueprint reference?

I have found one solution where I try to cast to ability blueprint “X”, and then call the event inside BP “X”. And if the cast fails, I cast to ability blueprint “Y” and call the event inside BP “Y”.

My problem with this solution is that it will eventually be a lot of abilities (200+), and this solution seems clunky as it would be a very long chain of casts.

I’m looking for a better way to do it and hope it exists :slight_smile:

how about making a parent? this way you only have to cast once and execute a function that every child has named the same, but which is different in code. the reference variable would have the type of the parent. this way all the childs would fit.