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.
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.
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.
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%
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
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?
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
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.
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!
This is a class array, so you can spawn actor from a concrete class directly
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.
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!
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
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:
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:
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:
Having an array of this struct makes it easier for us to affect the speed regardless of its length:
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.
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
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.
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