How to use " cast to …… " ?

Hi, I meet a problem. I try to call the “Leave” function in “BP_Character_Pragonist”, but I didn’t know how to connect the “object” pin in “cast to NPC_Novice”. Can anybody help me? Thanks!

This is BP_NPC_Novice.

Cast to node is used to specify an object.
For example if you use Get Player Character node,it returns you a Character variable,then you have to use Cast to node to cast the character to be “the character child 1,2,3 etc…”,in order to call functions inside those specific child.

In your case you don’t have to Cast,because you’re calling interface.
You should figure a way to get references to NPCs

1 Like

Thank you! My purpose is to call the function in “BP_Character_Protagonist”. I change a way to get references to NPC. Now it runs properly. Oh, I spell “protagonist” wrongly to “pragonist”.

Hello @ElectricRhino597 if you use the Get All Actors From Class node the interact with npc function will call for every npc in the world even if the player is not close. So i suggest to use Get Overlapping Actors node instead.

NOTE: In order for this to work you will need to add sphere collision to your mesh in your npc class

1 Like

OK, I understand " Get Overlapping Actors". My logic of judgement is when pawn enters into capsule collision of NPC, then call the related function in BP_NPC. Thank for your advice.

When the player enters the sphere collision (i called it radius in the photo) and presses the interact button then the event gets called. It works because radius default collision preset is set to OverlapAllDynamic. If you remove it you will notice that it doesn’t work.

I see. I have a deeper understanding of Overlap All Dynamic.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.