Animate multiple objects along spline (conveyor belt)

I am currently working on a project that requires a conveyor belt. What I need is to have 4 objects (lets say a cube, sphere, cylinder and pyramid) to be spawned and moved along a spline.

So far I have been able to animate 1 object along a spline using this tutorial: How To Make An Object Follow A Spline Path - Unreal Engine Tutorial - YouTube

However, I need a lot of objects so adding in hundreds of copies of the objects and then giving each a custom offset takes a lot of time, and is not very scalable.

Is there a smart way of setting this up?

Ideally I would have 1 spline and 4 objects that will randomly spawn on the curve and move along it until the end and then loop (or not as long as the animation is continuous) and I would have control over the speed the whole animation is moving, as well as the spacing between objects. I’m quite new to unreal and would love for a simplistic explaination if at all possible.

Thanks in advance for any and all help!

Edit: It doesn’t need any physics and needs to be setup without. Also, Niagara is not possible due to the nature of the project.

1 Like

Hi! This is a possible solution :smiley:
Result:
ObjectsMoving

First, I’ve created some blueprint actors for the objects. They are all children from the same actor blueprint in order to get the same code for all in one place.
image

BP_Object:
image

  • SplinePath is a SplineComponent
  • MoveObject is simmilar from the video. In this case, instead of the lerp, a multiplication is all what we need (due to the alpha works like a percentaje) but before doing it we add the offset to the alpha and get it’s fraction so it can loop when it reaches 100%
  • AlphaTimeLine is the same from the video
  • If you want this working with Duration (like the video) instead of Speed, do this change:
    From
    To

BP_SplinePath:
This blueprint is the same from the video but with some code in it.
Components and variables
imageimage
image

Code

  • You can play with the offset making it random, evenly distributed along the spline…

If you have any question or want to know something in more detail, let me know! :sparkles:

3 Likes

I haven’t tested this yet, but the amount of detail you have in your post… Bless you and thank you sooooo much. Will get back to you when I work this out! Thanks a million

Two things I’m stuck on at the moment.

Here you have Spline Path inside the Custom event. I can get the speed and offset, but I dont know how you got the spline path in there. What type of variable is it?
image

Later in the BP_SplinePath you have the variable type BP Objects with a purple grid. I can’t seem to find this one either :confused:

Sorry for the beginner questions, and again, thanks for the help, it’s greatly appreciated.

EDIT: Also, does your BP_Object contain all the geometry of the BP_Object_Cube, BP_Object_Sphere etc?

EDIT2: Ok, got the BP Objects variable to work but I dont have any default Value, im guessing this is because I built the actors wrong? I created a single Actor, named it BP_Gift (instead of BP_Object) and then right clicked and “Create Child Blueprint Class” and added my mesh to the child. This though makes it so the original BP_Gift is empty, but your example has mesh in it.

1 Like

Hopefully last question, How can I get the BP_SplinePath to cast to the Init_Object in BP_Object?
image
I can’t seem to find a way to call the function.

1 Like

It’s just an event in the bp object class.

I highly recommend figuring out the details of OOP and all the different ways to set something like this up and think through the cons and pros in all of them.

The video itself is really rudimentary and dirty way of doing things. It’s a red flag whenever you see GetAllActorsOfClass being used.

I can call the function in the BP_Object, but not in BP_SplinePath as its a different blueprint. Maybe I’m doing something wrong. I agree that I need to learn this better, but this project is a proof of concept with a tight deadline (Tuesday EoD) so was hoping to get some help and if we continue with unreal, will definitely learn the programming better.

@LucidGem Hopefully you have some time to help out again. The help people like yourself give to newcomers is immeasurable!

Don’t worry @PuckAmb , we’ve got this!

  • Purple grid:

This is a class array, so you can spawn actor from a concrete class directly
image
The default values will appear once you compile and you will be able to introduce your BP_Gift children

  • BP_Gift and it’s children

Don’t worry about BP_Gift’s mesh being empy. Mine has a default cube mesh but it is not necessary.
imageimage
The important is that the children have it.

  • Custom event variables

SplinePath is a SplineComponent. You will recieve this value from The BP_SplinePath directly and you won’t have to call GetActorsFromClass (I will explain this later)

Time for an Unreal tip!
DraggingVariables
This will create automatically the input you need instead of going to the function/event and adding manually a new input

  • Calling InitObject

You call InitObject from the actor you have spawned, not from BP_SplinePath

Spline is a SplineComponent, not BP_SplinePath itseft. With this you can give all the BP_Objects the SplineComponent value directly

@LucidGem I’m almost there I think. I’m still having trouble getting the Init Object node to work/appear.

I have this in my BP_Gift actor:

In my BP_SplinePath Actor I have this:

I can make the Init Object node appear by turning off Content Sensitive, but when I try to connect the Return Value from Spawn Actor to the Target [self] I get a “Actor Object Reference is not compatible with BP Gift Object Reference”. And same happens with the spline when I try to connect it:

Thank you again for taking the time in the weekend!

EDIT: For the array, I did have to add the 4 child actors myself, but don’t think that is a problem right?

As an alternative to method showed in this video, I would suggest the following approach:

  • Place all moving logic in 1 actors. This actor will do all the spawning and distribute based on distance between them along the spline. With this approach if we extend or reduce the spline length, the actors should be added / removed automatically. For example:
    SplineDist

  • To get constant speed regardless of the spline length, we need to somehow hold together a pointer to the actor and its distance along the path; for this we can use a struct:
    image
    Having an array of this struct makes it easier for us to affect the speed regardless of its length:
    SplineSpeed

  • Now its just place and play:
    SplineWorkdForUs


  • Construction Script:

    If you want to limit the amount, just change the condition in the while loop for ((fDistanceBetween * AddedComponents) < fSplineLength) && (AddedComponents < #) and it will only spawn what ever that number is.
  • Tick:

Hope it helps.

1 Like

Almost there!

  • InitObject’s target is the spawned actor
    image

  • SplinePath event parameter is a SplineComponent too
    image
    You have setted it to a BP_SplinePath
    image

  • Gift array default

Nope! No problem at all

@LucidGem

Hmmm, I changed the Splinepath in InitObject (in the BP_Gift Actor) to Spline Component like you mentioned. I can now connect it to the InitObject, but it wont allow me to connect the return value from the SpawnActor to the Target of the InitObject :confused:

I feel like I’m so close :angry:

Make sure Gift and Gifts are the same :thinking:
imageimage

EDIT: If it’s not the problem, try to compile and call InitObject from the spawned actor

Changed the name to Gift.

I think the main problem is that I can’t access the InitObject without turning off Context Sensitve

EDIT: Ah, I see that mine says “Actions taking a(n) Actor Object Reference”, and yours says “Actions taking a(n) BP Object Object Reference”

Yep, for some reason SpawnActor is taking Actor class instead of BP_Gift class

EDIT: Try putting directly the BP_Gift one moment

Unfortunately same issue:

In that case, something is wrong with BP_Gift.

  • Is it compiled?
  • You mentioned that you changed its name, have you fixed up redirectors?

EDIT: Is it possible that BP_Gift does not have the InitObject event?

So I just rebuilt the code in the BP_Spline from scratch and now it works! The only issue now is that it only does the animation for 1 loop until the last actor is spawned. Then it stops. The timeline is set to loop. Also, it only spawns 1 of each actor, and not a continuous random stream if that makes sense.

Nice!:sparkles:


Setting it to loop sould do the work… Hmmmm
imageimage


Ohhhh that changes things. This system spawns one object of each class you put in the BP_Gift array and makes an infinite loop with them. But they are always in the same order. Do you want it to be random and repeatable?

Preferably yes. The idea was that it would randomly shoot out a gift with even spacing along the path for infinity. Hope that doesn’t throw everything out the window.

Edit: pezzott1 looks like what I would need but that looks like UE5? and the code seems a bit scarier than what you have haha.

Idea would be that if the conveyor is 10 meters long, it would just shoot out Gif_Large, Gift_Round, Gift_Small, Gift_Large, Gift_Medium, Gift_Round, etc etc randomly until I stop the scene. They can be killed off at the end if that makes it easier because if they loop and the spacing is not perfect, you might see them overlapping when they get looped?

Edit2: sorry if my original post wasn’t clear. Rereading it now and I see why you built it the way you did, it’s exactly what I asked :confused: