Can't add skeletal mesh to USkeletelMeshComponent

Hi!
I have some questions regarding skeletal meshes and components.

I have a chest-like skeletal mesh with an open/close animation made in Blender. It has two bones. One root bone and one that is used for the open/close animation. In unreal I have a c++ class for that object, but I have problems to combine both.

What kind of UPROPERTY do I need? USkeletalMesh or USkeletalMeshComponent? I can’t assign the mesh to the USkeletalMeshComponent, when I made a blueprint of that class. There is a field with “None” inside, which isn’t editable. But when I add a skeletalmesh within the BP Window I’m able to assign it. But In the C++ Class I can’t set the USkeletalMesh as RootComponent, since it doesn’t inherit from USceneComponent. And how am I supposed to play the animation from USkeletalMesh ? It doesn’t have a PlayAnimation function like USkeletalMeshComponent.

Another question I have is about the PhysicsAssets. Do I need it or can I just use a simple Bounding Box for a chest-like object?

Thank you very much in advance!

BR

The Actor needs a USkeletalMeshComponent. To set the skeletal mesh of that component you have to call the function SetSkeletalMesh and pass your USkeletalMesh, which is the actual mesh asset.

Thank you for your answer!
So I will need actually both. But if my class contains USkeletalMeshComponent and USkeletalMesh and I have several instantiations of that class, does this cost extra memory? I basically need the mesh only once and set it as the skeletal mesh of the USkeletalComponent for every instance. But if I add the USkeletalMesh to the class and assign it in the Blueprint, does every instance of my class allocates memory for it? Or would the solution be to load it in the constructor with the help of ConstructorHelper and make it static?

You can access the SkeletalMeshComponent via Blueprint and set the mesh there. So you don’t need two variables. Just declare your Component like this:

UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite)

USkeletalMeshComponent* SkeletalMeshComponent;

If you compile and create a Blueprint derived from this C++ class you can acces all the settings for you skeletal mesh component.

Interesting! I already tried that of course, but my Blueprint seemed to be broken, because I created it long before and only reloaded it in order to get the changes of the class. I have now simply created a new BP from the class and now all settings are there.

Thank you!

Glad I could help :slight_smile: