Trying to make an object move back and forth

Hi everyone,

I’m currently trying to code a simple blueprint: Trying to make this object simply move swiftly on the X axis back-and-forth.

Here is the object:

Here is what I have on my Event Graph as of now:

And just in-case, my Timeline:

Any suggestions? Thanks in advance!

Hi. I not checked whole blueprint, but if you want it in game, you should connect it with Event Tick for loop movement. On Event BeginPlay it can be too fast to note. This is first idea.

As Vaheva mentioned, if you want things to move in game, you need to use the “Tick” event. Attaching all of your code to BeginPlay will attempt to run everything before updating. The exact timing specifics can get a little grey, but generally you can assume that Unreal will attempt to run any script you make as fast as possible.

The Tick event also runs as fast it can, but Tick is called on a time step. So every X milliseconds, depending on your frame rate, it’s called again. As such, you need to approach your problem solving differently.

I’m not certain if its properly arranged, but the rest of your code is on the right track for what you’re trying to do. Notice that the pin coming out of your MoveTime node says “update.” That node expects to be called multiple times, each time returning the next step of the curve until it reaches the end. It’s not a classic programming loop. As such, you should be able to just hook the “Play” pin to the Tick event.

As for actually updating the position, it looks like you’re just setting a class variable and not actually setting the SceneComponent’s position.

Hi again. I worked with your sample, and here is working solution. You miss few things, like a set world location, but not only. I created this on level blueprint, but it can be used elsewhere, rule is same. Here blueprint:

Do not forget to set mesh movable.

Generally I think better would be to create animation for movement like this, but it can works too, depending on your needs. Maybe this is not best version, but working as expected.

I changed values for better tracking, in example it moving 200 units as I remember and I changed time to 4.

Enjoy

133162-moveit.gif

Funny facts:

  • if you will create platform with this script, you can ride on it. It can work aslo very nice as elevator;
  • working with destructible, but with some weird effects - chunks moving too;

I’m glad it work. Your start help me a lot with this Switch, rest was easy with some experience.

That’s worked beautifully, thank you so much!

You can use AddRelativeLocation as well, and it is much more simple and easier. I attached the timeline here, too. Hope it helps. Cheers!