How can you have numerous instaced meshes moving along a spline? I want to create some tank treads. I have a spline BP and a Mesh BP that moves along it, it works great but I’m not sure how to add more instances to it.
Need more info. What are the other instances doing? Do you want them to follow alongside the other instances (maybe offset a little). Or do you want the other instances to have their own location along the spline?
Sorry that’s my bad, I’d like to have a closed looped spline (Tank Track Length) that can hold a certain amount of individual tank treads (Yet to be modelled, just using a small box for now) So I’d like to have the boxes slightly offset from each other other, all the way along the spline and rotating around it.
Essentially I’m trying to recreate this - Unreal Engine 4 Tank Track Гусеницы для Танка - YouTube
Red being the spline and direction of rotation, black being a few of the moving pieces
Would this work for you:
Does not really matter if these are actors, static meshes or ISM instances. Should work for anything with a transform. You could store offsets in an additional array since you cannot really conveniently store that data in an instance itself.
I think it might do, I’m a little stuck on a couple of pieces though, What is the “AllCars” variable type? And how did you get the “Car Offset” to show in the SpawnActor node?
You could use the BP you have now. You’d need to set SplineREF as an array and do a Get All Actors of Class (should probably use tags). Have each BP tread have a variable that stores its own TimeToComplete variable. You’ll need to increment them all. Or just set these as offsets from the main TimeToComplete variable. Your choice.
Then just do a For Each on the array of SlineREF’s in MoveObject event.
If these are instanced meshes… I think you can store custom data on each. So you could store the time offset there.
edit: I think the hard part will be keeping the treads linked together as they rotate around the front and back wheels.
edit2: Actually, you can just add the time offset as you iterate. You just need to store the time offset once. You’ll need to set it so the distance between each looks good to you.
These are the elements you wish to move. In your case, these would be the plates of the track. I assumed you’d be at least using Instanced Static Meshes for this.
And how did you get the “Car Offset” to show in the SpawnActor node?
You can expose variables for the actor constructor to use like so:
But please do not make each plate an actor, that’s a performance killer. What I suggested is merely a method for movement.
If you’re serious about tanks / vehicle sim, may I suggest you have a look at the some of the greatest threads out there:
Search anything by BoredEngineer, his t(h)reads (ehm!) should be pay-per-view, imho.
Sorry I’m not the best at blueprints so I’m trying to figure it out I’ve got the car offset showing now but I’m a little lost on the AllCars variable, is that referencing the Tread Mesh BP that I have? Or is it something else entirely?
And that thread is amazing! That’s almost exactly what I’ve been struggling to find
Or is it something else entirely?
Something else - you will need a lot of little meshes, right? You’re moving many pieces along the spline.
Judging by this reference pic, you’d need about 30 or so. In your original pic:
You were attempting to move this entire actor. But you should be moving the many small links of the tank tread and make them glide along the spline. Think of this actor as of the entire tread that moves the small bits about.
The script you have there should be a separate actor. Something along the lines of:
And the meshes could be instanced using this component. This actor represent a single tread and moves the plates / links.
Right, I kinda see that. So I’ve got my BP of a single tread. (The one that gets spawned in the spawn actor node) I have my SplineBP (The one with all this code in) and inside SplineBP I have a Spline and an InstancedStaticMesh, set to my mesh. But I can’t connect the instanced static mesh get reference into the add array part
All of the above should be in a single actor. There’s no reason to fetch the spline with Get Actor of Class. What if you have 2 treads (like in normal tank), it will not work anymore.
Start with something along the lines of:
Now you have tread actor that spawns links. Once you have those, you can try moving them.
Sorry for the slow reply, it crashed and had to remake it. So I’ve got all of that construction script in the same BP as the rest of it. But I’m still not sure what to put here.
@Everynone That’s pretty cool.
I was just thinking about how to keep each segment linked. If you set the pivot of each instance to one end and set X toward the other end, then you could figure out where the next segment’s location is and use a bit of trig to figure out the angle (similar to what Aim At does).
As mentioned above, please do not spawn actors for links. This will be a performance catastrophy. The original thread I posted was dealing with a car traffic system where each element was a car actor.
See the example with the animation above. We’re adding instances to the Instanced Static Mesh
component. If you decide to go for this method, you may want to take a dive and figure out how they actually work first.
I was just thinking about how to keep each segment linked. If you set the pivot of each instance to one end and set X toward the other end, then you could figure out where the next segment’s location is and use a bit of trig to figure out the angle (similar to what Aim At does).
There may be no need for that, the spline has a bunch of data we can sample:
If the meshes are designed well and populating the spline densely enough, this may be ready to go as is.
Right I see what you meant now! Sorry about that, so the construction script is pretty much working (Something funky going on with the distances between each piece) and I’ve tried connecting it to the original movement script but it’s moving the whole piece along the spline now like in the gif, I think I just need to plug something into the “Set Actor Transform” target but it wont accept the instanced mesh.
Looks like you moving the actor rather than the individual links. If the actor is moving, the spline is moving.
Something funky going on with the distances between each piece
Tick Use Constant Velocity
on the Get Transform at Time
node. This will normalise distribution, as the distances between the spline points vary.
Originally I was using “Set Actor Transform” to move the SingularBP along the SplineBP but since it’s now within the same BP I can’t use set actor transform, what could I use to replace that, so that it only moves the instanced mesh?
Construction Script where we create as many offsets as there are instances
The timeline is just 0-1 alpha. The Dirty
flag is optional but a good optimisation practice.
Could this not be done with custom-primitive-data?
Maybe, definitely worth trying. It would be much, much faster, for sure. This ISM approach is, kind of, OK, at best. And absolutely horrible if you have like 20 tanks.
@IlIFreneticIlI If you every attempt it, do @me. I’ve only had good times with custom-primitive-data so far. It’s an underutilised feature.
I lie, I got badly burnt with HISM + custom primitive data combo in 4.26 where it would jumble instance indexes due to LODs swapping.