How to possess hit actor

Hello! You should normally be able to do the following

  1. Cast the out hit actor to ThirdPersonCharacter (do not get the the class but cast it to the Blueprint) using the following node :

257650-fqsfqsf.png

  1. On success then get your controller and call posses pawn on it like so:

257661-fqsfqsf2.png

Hope this solves your problem! If it doesn’t work let me know

Happy coding!

how can I possess a pawn that I hit with a line trace?

I want to have mulitple characters that can be possessed all under the third person character parent class. But when I try to possess I can’t figure out how to get the pawn reference from the hit actor.

Pics:

Hi!

The Out Hit Actor probably needs to be casted. So drag a “Cast To ThridPersonCharacter” node from Out Hit Actor. Then from that cast you can call Possess!

That should work, please let me know if it does not.

Cheers!

I tried it it but cast is getting failed!

if your cast is failing then the object in doesnt inherit from class your casting to. put simply you arent hitting a thirdpersoncharacter.

How can I solve it? I wanna posses a Character(ThirdPersonCharacter) through a line trace which I set up in a Pawn Blueprint.

Thanks man! It worked.

Make sure the object you want to hit with the line trace blocks the line trace channel you are tracing in. For example if you are line tracing the visibility channel, all things that are blocking the line trace visibility channel will get hit! I suggest you make a custom Linetrace channel in the project settings that only the ThirdPersonCharacter class will block. Here you can read up about custom Trace Channels

My guess is that your line trace hits something other then the ThirdPersonCharacter before it hits the ThirdPersonCharacter. Make sure you have ignoreSelfActor set to true.