Casting to Specifc Actor

If the characters have the stats stored in their classes you don’t need a struct. You can just use the array of character references to refer to the specific subclasses and set/get the variables in the character classes themselves. The point of the character array was to give you a way to access the specific subclasses.(like casting an ability from one character to another)

The only reason mentioned the struct was because you made it sound like a 2d array would help you. The truth is the all variables in your characters are like one axis of a 2d array and a list of those characters is the other axis. So making an actual 2d array is kinda arbitrary.

Yeah I guess 2d array isn’t really that important.

Welp, this has taken a turn…

Spawn BP_Character at random location, and assigned them Stats. NumberOfParticipants is 2.

Then the Debugging, cuz I love them debugging… For Loop will print 1 out extra, for fail safe…

And it still fails… somehow…
Notice how none of the Name (Character XX ) or Speed matches with the Widget…

I’m not sure whats happening here but why don’t you just try pulling the variables out of the characters themselves, the struct is kind of redundant. Initially what I was saying is that all you need is an array of subclasses.(references to all the individual characters)

Well, my logic is that, the Struct is the only thing ‘persistent’ between transition from World Map to Battlefield, and Squad Setup menu and stuff.

Now since I start with the Battlefield, which is like the middle of the whole thing, I’m left with empty Struct… Should I make a quick Character Creation/Squad Menu first ? So Player can fill in the Struct, then once it transits into the Battlefield, the Game Mode can just Spawn Actors and assigned Stats based on the Struct already made… If I understand correctly, the Struct will also be used for selecting Target of each Character’s Action. (Heal BP_Participant with the least amount of HP, Attack Participant with highest Power, etc.)

Advice ?

Ps. I think I’m not exactly sure how Battle Array works yet. … It’s an Array with slots for BP_Participant. But isn’t that already what the 1st Slot of Struct Array for ? Right before Character ID.

Ok so bp participant slot is just so you can point to those characters.
(the physical characters, the objects you see in the viewport)

The struct isn’t going to have any relevant information in this slot if those objects don’t exist. (outside the battle)

You could use the struct to store the other variables, and carry them from battle to battle. Just update ones like bp participant at the beginning of battles, so you can say which character in the view port you are talking about when you want to do something to those specific actors. (ie. destroy a dead enemy.)

Battle Array is still useful because you can ask it for an index, that can be paralleled to the struct array. (ie. create a system where you left click on a character, it asks the the battle array what index the guy you’re clicking on is, then it can make changes to the structs in the struct array at the same index.(ie. Heal this character 20 hp.))

I see…

So, say, in the Squad Menu, Struct will have Participant slot empty, and everything else filled out.

Then switches to Battlefield… Game Mode will Spawn Actors based on the Class… [Note to Self: Change Class Variable from Text into Enum] (BP_Archer, BP_Swordsman, etc… all are SubBP/Child of BP_Participant), Set Actor’s Stats to match the Struct. Then update Struct with the Blueprint into that slot… I hope Struct will take all Actor Blueprint like BP_Archer, BP_Swordsman, just like it does with BP_Participant.

And that’s kinda what I was attempting… to Spawn Actors and assign them Stats from Struct, and then Set Struct to include the now Spawned Actor…

But somehow the Data/Stats don’t match.

You could use just one bp for all the classes and have them derive information about what skeletal mesh and animation they should have from the class variable in the struct. If you do this in the in the construction script of your universal character, it will spawn looking and behaving how ever you want that class to look and behave.

There might be good reasons you want to use different bps for each class too. Either way let me know if that becomes a problem when you get there.

Sounds interesting there about changing skeletal mesh based on class… I will think about it.

Anyhow, I just solved the issue I had with Data/Character’s Stats mismatched.

Now I can go back to whatever I was doing… Right, cast Healing on Character with Least Amount of HP.

Good luck!

If you want to heal the lowest character you’d have to create yet another array for integers and find the lowest value in that array.

Try to focus on one Problem at a time. If your problem is how to cast to characters in your scene, do not get into deliberations about how to organise data nicely with structs and 2d arrays, it will just distract you. You can always do that later when you refractor your code.

As I mentioned before just put a get all actors of class node in your game mode or whereever and save the array, and then you can work with the array.

Alright. I just used Get All Actors for Healing just now.

Healing on Actor with Least HP, done ! \o/
GFY Link

Now… I need to Spawn Enemy… I will see if I can use same BP_Participant, and just Tag them as Enemy instead of making a new BP.

This is my Heal Target with Least HP, seems messy but it works :slight_smile:

@enearle Letting you know things are working as intended now. Thanks much for the help, and will tag this question as solved now.

AwesomeI Happy to hear it. :smiley: