I’m trying to use the Mutable plugin from C++ but immediately ran into issues with the simplest possible use case.
I have the standard setup with a Customizable Skeletal Mesh component attached to a Skeletal Mesh component with the Customizable Skeletal Mesh component configured correctly with an instance and component name. When the Customizable Skeletal Mesh component is added from BP this works as expected and the skeletal mesh is updated to match the instance.
However, when it is added from C++ it updates the skeletal mesh once and then never again, and also hijacks the mesh in the BP viewport so you can’t change it back to any other mesh until you restart the editor. The only thing done in C++ is adding the UCustomizableSkeletalComponent the usual way with a pointer in the header and CreateDefaultSubobject in the constructor, and then configuring it in BP the same as before.
I just got bit by this too and I have an answer for you. If you look at the docs it gives you a hint but it doesn’t really say this out loud, you need to use NewObject, not CreateDefaultSubobject
No idea why the docs don’t call this out but I had to do this in BeginPlay:
Ah thanks, I did see the C++ section in the docs but from what I gathered it looked like it was for runtime use since it didn’t create a default subobject in the constructor. I didn’t want to go down that route because if you do this on BeginPlay or PostInitializeComponents then it won’t show up when you change instance in the editor.
As I was looking into this more I remembered an alternative to UCustomizableSkeletalComponent called UCustomizableObjectInstanceUsage. It serves the same purpose but is just a UObject instead of a component, so it’s a bit cheaper too. I got it working and updating in editor by overriding OnConstruction and creating it there:
Not sure why they don’t mention this approach in the C++ section because UCustomizableObjectInstanceUsage has a nice description in the code, to me it is the cleanest way to do it as you avoid having another component clutter the list and also save a bit of performance.
Interestingly when I was debugging this the Component actually has an instance usage member. When created via CreateDefaultSubobject it seems that the UCustomizableSkeletonInstanceUsage object inside the UCustomizableSkeletonComponent doesn’t get copied from the CDO which causes it to not work; UpdateSkeletalMeshAsync on the Component will just early out if it has no InstanceUsage object. No idea why this happens exactly but hopefully someone smarter working on Mutable could fix it / explain more clearly in the docs why the Component seems to drop its InstanceUsage object