GetEnemyLocation

A new quest for you men! I basically have a script written with a trace channel that tries to get the location of the pawn touched. The cast of course succedes but I don’t know how to make it permanent. Basically I want to know the location of the pawn touched last time, all the time. Get I have a glimpse? kind regards, Alex

Right click on the variable being output by the cast and click store as variable. This will add the variable automatically to the list of existing variables in your blueprint. You can use it any time you like. If you are not sure it is already set, you could use an IsValid node on it before getting its location.

I don’t understand. So i have the position in X Y Z but I can’t get that store as variable.

I think I am missing something…

I think it’s only get the location without keeping track of it.

What you’re doing after the Cast to Pawn is setting “Lock On” to true, setting the current location of that pawn as a variable, and printing that value as a string. This all happens one time when you initially cast to that pawn.

What you should do is right click on the “As Pawn” output of the Cast to Pawn node and promote that value to a variable called PawnTouched. Any time this cast node is called, it will change the value of this PawnTouched variable to the new Pawn actor. (If you need to track multiple pawns in this way, you would instead add that to an array of pawns.)

Then, don’t get the location after the cast. Do it on the Tick Event so that it updates every tick. (Or set up a Timer By Event loop to check every n seconds.)

EventTick Setup:

Timer By Event Setup:

As for Lock On, you could keep this as it is if you just want to tell your character that he’s locked onto something. Or you could move it to the AI Pawn and get/set off of casts. Just depends what mechanic you need that variable to drive, really.

Store the pawn instead o the actor location, and every frame you need the location you can do “Get Actor Location” on the stored pawn.