The order of execution between C# Mesh deform and Skinned Mesh deformations

I wonder if scripted actions on mesh such as setting vertex positions are executed before skin deformation or after it? Also, if the scripted deformation is executed before skinning, is there a way to make it execute after, as a post-processing effect? I’ve made useful “squash and stretch” animation modifier in Blender, but havent tried porting the code to Unity yet. The main advantage of this thing is that it is executed in world space and after skinning. If it is not possible in Unity, then better not to bother.

Here is some timing diagram help:

Good discussion on Update() vs FixedUpdate() timing:

1 Like

I dont get where SkinnedMeshRenderer component belongs on this graphic :face_with_spiral_eyes: To Scene Rendering, since it is Renderer?

You’re right, it’s not called out.

But since there is LateUpdate and then OnPreCull, it has to be somewhere between there.

I reason this because LateUpdate() could change meshes

OnPreCull must have all the meshes as they will ultimately be to cull.

1 Like

This tutorial on making your own custom player loop in Unity shows a method for seeing all the sub systems in each of the player loop stages.

In PostLateUpdate I can see ‘UpdateAllSkinnedMeshes’ which might be what you’re looking for.

And if it’s not at the right stage, you can always add in your own custom player loop.

2 Likes

Seems to be it. Only practical testing will tell for sure. Thanks

Ok, I’ll check PreCull as well

The question is what do you actually expect to happen before or after skinning? For example when GPU skinning is on, the skinned vertices are not even present on the CPU side. Even with CPU skinning, Unity does not provide any direct access to the skinned mesh. The actual “mesh” that is referenced by the SkinnedMeshRenderer is never modified. The skinning only takes place in a copy of the data on the native C++ side. Unity provides the BakeMesh method for quite some time now which allows you to read-out the skinned version of the mesh at any time. However that’s just a copy of the mesh and not the data Unity actually uses.

There is no way to directly get access to the skinned data that the renderer uses. So if you really want to modify the mesh data after skinning, your only option at the moment is to use BakeMesh manually to create a skinned mesh on the fly, modify that mesh and use that mesh with a normal MeshRenderer. Even when caching and reusing the temp mesh and using a cached List and GetVertices to read out the vertices, I’m pretty sure performance wouldn’t be that great. It may work but is probably significatly slower, especially since you are now forced to do CPU based skinning.

1 Like

Oh, Bake Mesh workflow sounds complicated. Is performing deformations in vertex shader an alternative (to do something post skinning)?

Yes, sure. However depending on what kind of “deformations” you have in mind it can get complicated as well ^^. If it’s really just about uniform stretching along an axis and a uniform offset, that’s quite trivial. You can even use _Time in the shader to do your “animation”. You may use a multiplier to turn off your procedural animation in the shader which you can set from the outside.