Casting to another (NPC) pawn

So I’m trying to create a party system for a JRPG and I think my idea is correct but my method isn’t. Firstly I want to check if the character pawn is spawned in the scene so in the character BP I have made a variable that starts once the pawn is in the scene.

238501-check-if-spawned.png

Next I want to have my menu BP to get this variable when i pause the game and if its true, it will create the character portrait in the menu. So far, this is working how I want it to. The issue is when I want to add a second “party member” who isn’t controlled by the player. I cast to this second “party member” who has this character check variable and use the same setup as my player character except this time it will create another party member portrait widget.

This is where my problem starts. The second frame doesn’t show up at all. I believe that it could be an issue with the casting? I don’t think I should be using the Get Player Character for my casting to the other party member, but i cant work out what I should be using instead. I get the feeling that this is something really dumb and easy to fix. Any help will be much appreciated.

Couple things to note:

1 - I’m sorry to say, but your boolean is useless. BeginPlay is the first think to be called when an actor is spawned, so as long as the reference to the player isn’t null, you can make sure the actor is in the scene.

2 - You’re right! By getting the PlayerCharacter, which is the Character actor that’s being controlled by the character, when you cast it to an NPC, the cast will fail. Instead, try using “GetAllActorsOfClass” so that you can circle through all the characters, even those who aren’t controlled by the player! That’ll work as long as they share a base class, like Character for instance!

■■■■, and here I was thinking I was some sort of genius for that bool hah. I tried what you said and its working perfectly, it’s cleaned the BP up a lot too, thanks!

Well everything was working perfectly, or so i thought, now i have a new issue, The frame shows up which is great, but it shows up when the 2nd party member isn’t even in the scene? I get the feeling using the “GetAllActorsOfClass” is just picking up everything that is of the character class instead of the specific “2ndmember” class (The second party member is just a duplicated thirdpersonBP with the movement components removed)

Hmm, can you show me your blueprint then?

You’re not using the node properly: the node returns an array with all the actors found in the scene with the given class. If the array is empty, that means no PartyMember2 is in the scene, if there is at least one element in that array, there is at least a party member in the scene.
You need to check that in order for it to work.

So I’m still using the bool on the 1st party member as it lets me check whether it is working or not when I turn it on or off but once I’m sorted I’m hoping to get it to look like the 2nd party member line.

I’m using the “GetAllActorsOfClass” and have chosen the 2nd party member BP as the target. This gets my frame to show up but works regardless to whether the 2nd party member BP is in the scene or not.

No problem :wink: and don’t forget: most of the time, the best solution is the simplest one!