i want to make snake Dragon model to follow the spline path

i have a snake/Chinese Dragon model rigged and added control rig to it and i want it to follow the spline path as that would be way easier to animate a snake like models .
i can make it follow the spline path but i want it to bend when the spline path curves and follow it properly not just static .
i saw a Forum with the exact same question and it had proper solution like i want but its not working for the control rig , skeletal mesh of the dragon , Here’s the link of that forum:- How can I get this Cylinder to snake along this spline path.... looking for help or a tutorial . (Watch the video upload by @ClockworkOcean , that’s what i want exactly with the snake dragon model ).

here is some more details what i have done so far by watching tutorials and articles :- Zof - Google Drive

i would request , if anyone can help me little quicker because my deadline is very close , pleaseee

Here’s a youtube video where this person did the same thing but in blender can anyone guide on how to do this in unreal engine

output

Hi Krishkrish,

To get your mesh to follow a spline, you’ll want to use the PoseableMesh component.

  • Create a blueprint with a SplineComponent, add it to your scene, and create your path. I’ve ticked the Closed Loop option on the component.
  • Create a new blueprint actor for your snake dragon, and add a poseable mesh component to it.
    ** Set it up with the skeletal mesh and materials
    **You should also set the Bounds Scale on it to be fairly large - I did 1000. This controls whether the mesh will be rendered or not depending on the camera and its starting position. There are likely better solutions to fix this issue, but this will get you started.
  • Give the snake dragon a variable to reference the Spline object
  • For the snake dragon logic, you can follow this blueprint:

A few caveats:

  1. My snake mesh here is very similar to the one in the monkey video - has simple list of bones equally spaced apart. Depending on your mesh, you may have to edit the logic about listing and positioning the bones
  2. There’s some best way to rotate the snake that I don’t quite understand yet. I ended up doing a manual 90 degree Z rotation in the logic, as well as giving the PosableMesh a Scale of (1,1,-1) to flip it up the correct way.
  3. I found when I set the bones on the spline, the mesh shrank, so I scaled it back up in the SetBoneByTransformName node with (10,10,-10).
  4. Currently my demo only works well in the X,Y plane. If I tell the snake to go up or down vertically it starts to look like a staircase. I’m likely doing something incorrect with the rotation I haven’t figured out yet.

Hope this helps!

Thanks , i will try this but if possible can you please share a screenshot of the blueprint event graph i want to see the all left panels like what varibles you add and what type it is as i am new to ue5 it would help me to try you solution

also as you mentioned the snake cant go it z axis but i wanted my snake to go in z axis also as that would make the chinese dragon animation way more better

but still respect for you that you made the snake follow the spline x and y axis , i have searched too much about this and there was no single one to do this on mesh component as far as i searched

also i heared about poseable mesh first time

Hi Krishkrish,

Sure:

  • The spline is a variable to a reference of whatever your spline blueprint class is.
  • The Bones is an array of names. (If you’re new to arrays, you can just think of it like a list of names)
  • Everything else is a float - a number with a decimal.

The only variable I’m setting manually in the details panel is Speed, which I set to 800. I just played around with a value until I got one I liked.

Ah, I see I also used a “Get Snake Length” function I didn’t include in the previous post. Here’s the definition for that:

As for having it go up and down in the Z axis, it can - it just looks strange, and almost certainly has to do with the rotation. Depending on the rotation of your model, you may need to play with different values of rotation and scale for the X,Y plane too. Experimenting with different rotations and scales will probably fix it up.


Also, a tip: If you copy and paste a blueprint from blueprintue.com, and then right click on an variable in the graph, Unreal will give you an option to Create Variable that automatically has the right type.

output

New improved version that can travel in all 3 dimensions.

I’ve updated the Blueprint logic with the fix. The two snippets are:


Rotation Fix Details

In case others run into the same issue, the problem was in how I was doing the rotation.

output

When I initially positioned the bones on the model, I got this effect. The bones are rotating to the path correctly, but they’re all offset - you can see the snake’s head is upside down and pointing to the screen’s left.

The mistake I made was in trying to correct this offset. I used the CombineRotators node, but forgot that - unlike location vectors - it matters which order you input the two rotators.

The correct way to do it is to apply the offset you need in the A input (which I got just by playing around with it), then apply the spline rotation in the B input. I had been doing it backwards, and had to apply negative scales and other hacks to try and correct it - which worked well enough until I started using the Z-axis.


Snake Model

If you’d like to play with this exact snake skeletal mesh, you can download it at: Simple Skeletal Snake - Download Free 3D model by JoeProgram [f92bead] - Sketchfab

1 Like

You are Brilliant man , i lost all the hopes of doing the chinese dragon animation in my project but thanks will do this asap , Thank you

Awesome, glad it was helpful! If it looks good to go, could you mark this question as answered? It’d be a big help to me :smile: .

Yes , Marked as solution

if you are available can we please be on call/discord or some , i have many questions while executing and have very very less time ( i have to complete this dragon spline animation today its the last day ) :smiling_face_with_tear:

Hey @JoeProgram i got this error and i was not able to fix this one , even though i have paseted the get snake length code in it

found one fix but i dont think thi will work i drag and drop the new get snake length and it looked little different from yours

also do i have to type the names of the bones in the default value of bones node ( the model i have its root bone starts from middle of the model and then the hierarchy goes to the face { i think thats opposite of what it should be, isn’t ? } )so in this case should i follow any order in adding names the bones node or the order doesnt matters ?

heres the dragon

Yep, good questions.


The difference between these two is the top one is called a “pure” function. See how there’s no white execution line going into some nodes, but there is on other nodes? Any node without that line is “pure” - which is a setting you can toggle on by clicking the function name and turning it on in the details panel.

A “pure” function just means the function won’t change the value of any variables. It can make the code look a little more organized, but it’ll work fine either way.


Ah, yes - since your model is more complicated than the simple snake, there will be a few changes.


You can delete this section that automatically grabs the bones and puts them into the array, and instead just type their names in manually. You won’t need to add the names for the arms or the feet - just the names for each bone in the spine/tail.


Another possible difference is if the bones you want to move are spaced equally or not.


For the simple snake model, each of its bones are are spaced the same distance apart.


That distance is important to know, because we have to manually calculate the position for each bone on the spline. Since all bones are equally spaced, we can calculate that distance once, store it in “Distance Per Segment” and use that in our loop.


If the bones are not equally spaced, like above, then you’ll need to either calculate or manually type in the distance each bone is from the root bone- probably in a new array.

GetSnakeLength may or may not be useful in that case. It’s getting the first and last bone to find the overall distance of the snake.


You could just type in the head and tail bone name in the GetSnakeLength function, but it’ll just depend on your model’s setup whether that’s useful or not for figuring out the per-bone distance from the root.


Yep, there will be some changes since your model has the more traditional skeleton setup. The ones I can think of are:


Since the bones from the pelvis to the head will be pointing forward, and the bones from on the tail should point backwards, you’ll need a different rotational offset per bone, probably another array. In the simple snake, I was able to just type in one number for the bones, since they’re all pointing the same way.


This part will also need to change. Here I’m multiplying the array index by that distance per segment to calculate how far the bone is from the root. If you have that manually typed in, you can just look it up in an array. Some of the distances will be positive numbers - for the bones from the pelvis to the spine, since those should appear in front of the root - and some will be negative - for the tail bones behind the root.

In this case, the main thing with ordering is to make sure that you have all these things in the same order:

  • The list of bone names
  • The distance each bone is from the root
  • The rotational offset for that bone

Unfortunately, I’m not available for discord or a call - forum posts is the best I can do.

I’m rooting for you!

@JoeProgram Check this video , i think every thing is good , just the roatation value and the multiplaction of array etc part is at default which you have set , but i think the model should have shown atleast some changes , but its normal no changes are there , and while simulating it disapears and after the pause theres lots of errors

and i have skipped this part as this is to be done if the bones position are not equal , but in my model the distance is equal , am i right ?

Yeah - that’s a good approach. Getting the model to first move on the spline at all, and then fixing up any spacing issues sounds like a good process.


This error means the code is trying to read a value that is currently set to “None.” If you look at the Details panel of the Joe_Fixx actor, you’ll see there’s a new variable there for Spline and SplineComp.

Open the dropdown for Spline, and select one of your spline objects in the scene. That will let the dragon know which spline you want it to follow.


(FYI: You don’t have to set SplineComp manually - this is the bit of code that does that, where it plucks the Spline component off the spline actor, so it can read in the information it needs)

@JoeProgram so i have removed the spline component that was added by myself but still in the spline variable drop down i cant select any other thing like I made a new blueprint class with a spline component in it and that was also not getting detected in the spline option

or there any other way to add a spline component in the viewport ?

i searched about it and this page said the same steps like i did to add spline component :-How to Edit a Spline Component in the Viewport | Unreal Engine 4.27 Documentation | Epic Developer Community


Good call on posting the videos - definitely making it easier troubleshoot.

Your problem is right here - the variable type of the Spline Variable is set to “Joe Fixx.”

You’ll need to switch that to be your Spline Blueprint type. When you do, you’ll get a warning, but accept it anyway. You’ll probably get some errors in your blueprint when you try to compile - just delete any old “Spline” nodes, and drag the variable back in and hook them up the same way.


What’s happening here is the variable type tells Unreal what kind of information is in the variable. This code is looking for a Spline Blueprint Actor that has a SplineComponent. Once you switch this over to be your Spline Blueprint Class, you can pull down that dropdown in the scene and select the spline actor you want to move it on. You’re currently seeing the Joe_Fixx dragon show up in the dropdown option, because the variable is set to be the Joe_Fixx dragon variable type.

@JoeProgram
Yayyy , Thanks the Dragon have started moving on spline now i think i have to play with rotation and the multiplication of array you told ( i dont know what to do change in multiplication of arrays etc )

and i see the tail of dragon is not properly aligned

also when i changed the scale the model got stretched so is there any other way if i want to scale up the model ?

one question , do changing the sequence of the names in bone array matters or not ?

i think i have to play with the calculations something

( by changing the rotation + the multiplication value i managed to set the rigth direction of the model but still the tail is in the oppposite directions means , its inside the model



Nice!

The names of the bones in the array can matter - it depends how you set it up. Since you’re just getting started, I’d recommend a setup like this for your dragon:


I think you’ve already got your name array setup something like this - one name per bone you want to place.

image
I’d recommend making another array variable, but this time it’s an array of rotators.


You’ll make one entry for each bone in your bone list - and they’ll need to be in the same order as the bone list.

You can just fill in your current working value of (180,180, 270) for each of the bones that are working properly. When you get to the tail bones you can try different values.


Then you’ll read off the values you typed in in place of the current (180,180,270).

What this loop is doing is:

  1. Get the first bone in the name list
  2. Do some math to figure out where it should go
  3. New: Get the first rotation in the rotation list
  4. Set the bone’s location and rotation

and repeat for every entry in the two lists.


FYI - watch out if the two lists end up being different lengths - that’s a common bug for a setup like this, and the engine may or may not start throwing errors. Just something to check if you need to troubleshoot.