(Posting this in ue 4.21 but i think this applies to any other 4.2 version)
First a little context:
I am working on a old style final fantasy-like battle system, where the map has 10 slots, and they get occuppied by 5 enemmies and 5 player characters (controleld by 1 player).
When the player gets transfered to the battle map, the game sets the enemmies to ocuppy slot 1 to 5 based on a randomized variable, or preset variable (depending if its a random encounter or a storyline battle) and occupies the slots 6 to 10 depending on the members on the player’s party.
Both the enemmies and player characters are pawn classes, with skelletal mesh, cammeras, variables, etc. they all have float variables named, i.e “Health” and “Defense”.
Now to handle the variables as global, i have a gamestate class called “playerslots” that contains variables named “party#” and “enemy#”. These variables are accessed by the battlemap blueprint to know what players and enemmy class pawns spawn in the battle map, that part is working all good.
Now, “playerslots” also contains variables named “player#health”, that i need to fill accordingly with the “health” variable of the pawn class on that character, NOW i can achieve this using the “cast to Xplayer battler class” node and retrieve “health” variable from there and set that to “playerslots” using the “cast to playerslots” node. IT WORKS. But for that i need to set a large array of “if” conditional branches to check wether the “party#” variable equals sussie, or anita, or clementina, etc etc etc. In the case of the player characters this is not a huge issue since they will not be more than 8 options or so.
The problem comes when the game will have a lot of possible enemmies where to check, and accordingly to that enemy, a LOT of “casto to this enemy” node in order to assign the “health” and “defense” variables from that pawn class into the “playerslots” and then be used by the battlemap blueprint.
The problem could possibly be solved if i could somehow use the “cast to” node to whatever class it’s actually in the “enemy#” variable, that is a class variable, whatever class the variable is currently filled in with will be a pawn class, that contains a float variable named “healt”
[enemy#]->[cast to (this)]->[get health]
is possible? if so, how? if not, then how could i solve this withut using 100+ conditional “if” branches and everything that comes allong with them?
Thanks in advance!