Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: UE 4.12
more ▼

asked Apr 05 '17 at 09:13 PM in Blueprint Scripting

avatar image

8 1 2 5

avatar image Vaheva Apr 05 '17 at 11:59 PM

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.

avatar image CDMcGwire Apr 06 '17 at 01:22 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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:

alt text

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. alt text


alt text

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;

movable_mesh.png (224.3 kB)
move_time.png (38.5 kB)
moveit.gif (891.4 kB)
more ▼

answered Apr 06 '17 at 03:34 PM

avatar image

1.3k 24 30 53

avatar image RobHayes01 Apr 06 '17 at 06:35 PM

That's worked beautifully, thank you so much!

avatar image Vaheva Apr 06 '17 at 07:23 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

alt text

alt text

movealpha.jpg (16.8 kB)
more ▼

answered Jan 17 '18 at 09:43 AM

avatar image

6 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question