[SOLVED] Why I need to set a variable before getActorLocation?

Hello guys! I’m a beginner UE4 developer and I’m always making me questions about all that I see.

I made a litte enemy from a tutorial but I don’t understand something.

Why I need to make this vector variable to make it work?

Then why this next options don’t works and get bugs?

Thanks alot for helping me to understand better BP.

Cheers <3

Timelines only work properly if the start and end points are fixed. That’s why you need to set it.

If you sample it in real time, as you are in the later pictures, something will happen, but it will not be what you want.

Take a look at vinterp, that DOES use sampling in realtime. It’s the other way around, you can’t feed it fixed locations.

1 Like

Basically, because getactorlocation hasn’t execution pins (white triangles to connect white lines), you really call it when the node with execution pins connected to it is called.

So, in the first image you are getting the actor location on begin play once, when the “Set Posicion Enemiga” node is called and stored in that var. So you get the location of the actor and store it only 1 time, at the beginning.

So in first image goes like this. Game Starts, gets location of the actor, let’s say is at 0 (0,0,0) but to make it simple imagine it moves only in 1 direction. Then you get a value of 1 in the timeline, you have 0 (posicion enemiga) + 1 (from timeline) and you move actor to position 1. Then you get 2 from timeline 0 (posicion enemiga) + 2, so you move the actor to position 2, etc…

In the other images, you are calling getactorlocation each time setactorlocation is called, basically each tick. So you are getting the actual location of the actor each tick.

So in the other images, you 0 (getactorlocation) + 1 (from timeline), you move actor to location 1, but here is the difference, you get 2 from timeline, then you have 1 (getactorlocation) + 2 (from timeline), so you move the actor to location 3.

First image:
0 (posicion enemiga) + 1 (timeline) = 1
0 (posicion enemiga) + 2 (timeline) = 2
0 (posicion enemiga) + 3 (timeline) = 3

Other 2 images:
0 (getactorlocation) + 1 (timeline) = 1
1 (getactorlocation) + 2 (timeline) = 3
3 (getactorlocation) + 3 (timeline) = 6

1 Like

Hey thanks to both for taking the time to help me, I really appreciate it soo much! <3

Ohhh!! That makes sense why the actors were moving so fast and disappearing from my view.
So, If I understand correctly. Using the variable, Im saying to the compiler to only get that location just one time. But with the other methods, Im getting the location per tick. Am I correct?

So I have another question. I thought what you was saying me before but why I didn’t trust on that thought was because, ok its storing the variable but It will be called again and again like “GetActorLocation”, no? It’s just trespassing the number to a variable, why I need that variable?

But you saying me that it only calls it 1 time cause the pings. Im correct?

Sorry if my English its bad. I’m not using translator cause I wanna practice it writing hehe


1 Like

Don’t know how to explain this in a easy way, I will try.

  1. Game Starts
  2. You execute (white line) “set Posicion Enemiga” wich calls GetActorLocation and stores it.
  3. You execute the Timeline “Movimiento Enemigo”
  4. You execute the “Switch on Movimiento”, which is executed each time the Timeline “Movimiento Enemigo” is updated (basically each tick).
  5. You execute SetActorLocation, wich calls the Add node, wich gets the values from Posicion Enemiga and XMov, YMov and ZMov.

    Notice how I removed the nodes, because in point 5, you are “calling” the set node and timeline node, but not to execute em, you are calling em so they only tell you the values they have stored. While the Add nodes are executed because haven’t got execution pins (white triangles), like would happen with GetActorLocation if it is connected directly.

Then 4, 5 repeat again and again and again with each update of the TimeLine.

I think you speak spanish because the nodes names, so I will try in spanish too:

Los nodos que no tienen el triangulo blanco se ejecutan cuando el nodo con el triangulo blanco al que están conectados se ejecutan. En el primer caso, el “GetActorLocation” se ejecuta/calcula cuando se ejecuta el “Set Posicion Enemiga” y guarda la posición ahí.

Luego los SetActorLocation llaman al nodo Add que se ejecuta, el cual llama al Timeline MovimientoEnemigo pero para obtener los valores de XMov, YMov y ZMov y al nodo Set Posicion Enemiga, pero no para ejecutarlo y que se vuelva a guardar la posición del actor, solamente para que le diga el valor que tiene guardado, que es la posición del actor cuando empezó el juego.

Si no pones el Set Posicion Enemiga, lo que pasará es que el SetActorLocation ejecutará el nodo Add, el cual llamará a TimeLine MovimientoEnemigo para obtener sus valores y ejecutará el GetActorLocation para saber donde está el actor, pero como mueves el actor, el GetActorLocation te irá dando la posición que tiene el actor cada vez que se actualize el TimeLine, en lugar de la posición en la que estaba al principio. Por eso se guarda la posición inicial en una variable.

Creo que lo entenderías más facilmente si en lugar de conectar el Set PosicionEnemigo directamente a los nodos Add, rompes la conexión que tienen (las 3 lineas amarillas que van del Set Posicion Enemiga a los 3 nodos Add) y arrastras la variable Posicion Enemigo del panel izquierdo y lo añades con un Get, el cual conectas a los nodos Add.

1 Like

Hey @ikifenix I really appreciate so much the time and effort that you are putting to helping me to understand. I think I understand correctly now.

So, in resume:

When I use the variable, the “getActorLocation” just get called one time because the execution of the “Set Variable”. Then, the timeline takes the information inside the variable each tick but only the position of the start. Not like in the other cases that is updating the position always because is not storing that start position.

Am I correct?

Thanks a lot.
Cheers <3.

Do u mean this?

I think I understand it perfectly now! Thanks a lot <3
Btw, your spanish is perfect, are you from Spain?
Cheers! <3

Yes, exactly. It is the same as connect directly the Set Posicion Enemigo as you had before, but now you can see in a easyer way that the Set and GetLocation aren’t being executed at all after the Timeline the Set was just being used to get the value stored as a Get, and I am glad it helped you to understand it better.

Yes, from Spain.

1 Like

Thanks a lot!

1 Like