Download

Delay and Direction

I am very new so forgive me, before posting here I have looked over the documentation and watched several youtube tutorial videos, in hopes that I would find my answer ( or clarity)

I purchased a book “*Blueprints, Visual Scripting for Unreal Engine” * by Brendan Sewell, from Pakt> publishing. I am currently on the first chapter (again I am very new) but I have stumbled across something that confuses me, and have yet to find a satisfying answer.

The code is working as intended, I am trying to better understand exactly how it is working. I have attached a screenshot of said code for better representation.

My questions/confusion is as follows.

Is the delay (set to 6 seconds) actually controlling the distance (in this case time) the actor will travel?
If that is the case then are the values in the direction node arbitrary as long as far as 100y being no different than 1y?

I have experimented with changing the values, the longer the delay, the greater the distance the actor travels, and likewise no matter what value I put in the Y direction node (one being positive, the other negative) no change is felt.

I do understand that it would seem I have answered my own question, and perhaps I have, but that only brings me to another question, why use a delay to determine the distance and actor travels? Isn’t there some node the would have that specific thing?

Again, I am a newb, and I am sure it shows. Thank you for your time. Look forward to any feedback

@avabava2011 I have to say, that’s a pretty strange piece of code. Basically you’re running 120 transforms per second ( or whatever your frame rate is ), all with a 6 second delay! ( buiding up a huge list ). It’s possible it’s in the book to teach you about the pitfalls of using Tick.

A much better way to achieve the same effect is to use ‘set timer by event’ ( imagine it’s called ‘call event using timer’ :wink: )and connect the red pin to the SetActorTransform.

Or, use a timeline :slight_smile:

Regarding your question about how this amounts to the actor moving some distance, I assume on the left of the orange transform line, you are making the transform using your direction variable? Although even then, it looks from your code like the actor would just jitter about on the spot.

Thanks for the reply @ClockworkOcean , I will have to take your work on the quality of the code as I am new, perhaps later on in the book they will go over a more effective approach; if not I have made notes on what you said and will look further into your suggestion.

I am going to upload the other portion of the code, I probably should have done that, to begin with, but in haste, it slipped my mind.

So when the scene is started, or when I hit play, the actor(s) assigned this blueprint move along the Y axis for 6 seconds then reverse course go back 6 seconds. This repeats itself endlessly, by design ( in accordance with the directions of the book)

So it is working like it, or the book intends. My confusion is with the Direction Node and in part with the Delay node.

I am assuming the Direction node is just that, it dictates the direction, not distance. If that is correct, then the value placed in that node (10 and -10 respectively) holds no significance other then denoting a positive value and a negative value, is that accurate?

I was wondering if there is some sort of “behind the scene” thing going on which led to the book specifically giving me those values (10,-10) Perhaps a form of z-indexing just as an example.

I have adjusted the values and have seen no difference in behavior (providing the delay stays the same)

From what I can tell it is the Delay that is actually governing the distance that is being traveled. Am I correct in that assumption?

Thanks in advance, sorry for not being very concise.

@avabava2011 I’m not surprised you’re confused by this code. Basically, what its doing is ignoring anything you type into the direction variable ( because it gets normalized, ie set to 1 ), and adding it to the mesh position every frame.

I guess the delay is what determines how long to wait before travelling in the other direction.

It runs a mesh transform every frame, each one of those waits 6 seconds and, alternately, increases or decreases the offset, which gets multiplied together with the time difference… yikes!

Don’t get hitched up on this, try something like: WTF Is? Set World Location & Rotation in Unreal Engine 4 ( UE4 ) - YouTube which will explain how humans do this… :slight_smile:

I agree with @ClockworkOcean that setting the Direction on Tick by a delay is a bad idea and should be done with a Timer.

A normalized direction where x and z is zero will always result in 1y (Right) or -1y (Left) so that is why it doesn’t matter what number you set y to it only matters if it is positive or negative.

There is 3 ways I can think of on the spot that would have you know when you moved a certain distance that doesn’t involve physics.

  1. You do like your book suggests and use time and speed to determine distance. If the speed is constant this is an easy and efficient way of measuring distance traveled.
  2. You add the relative distance you move every frame and check that distance traveled every frame and change direction if you have reached the desired distance.
  3. You measure the distance from your start location every frame. If you only move on one axis this is a simple subtraction but if you move on two or more axis this is a square root operation and becomes the least efficient of these 3.