Changing SkeletalMesh and AnimInstance at Runtime (FIXED)

Hey everyone,

I have had a fun time recently trying to implement a system that allows to store pointers of SkeletalMeshComponent objects within a character. The main characters intention is to grab other Actors Mesh Components and switch to them during gameplay. The character can also switch back to its default mesh.

The issues I’m having is I can’t just store away the pointer to the Mesh because when I change the main characters mesh, he then can’t resolve the pointer to a default skeletalmesh and animinstance.

At this point it is working but I had to use a PCIP.CreateDefaultSubObject in the constructor and set the SkeletalMesh and AnimInstance in PostInitializeComponents(). This gives me the following errors for any Blueprint instance within the world:

I have tried many different ways of changing the mesh using the array like GetDefaultObject(). The main issue here is either I get null pointers or errors. Below I have given the .cpp code of my Character Class.

[Pastebin Link][2]

Is there anything that I am doing wrong? Would you recommend a different approach?

It seems so obvious now. Instead of having the one class I created a new class inheriting the BaseCharacter for just the player. Here I put all of the change Mesh functions.

In my new class I added the variables:

UPROPERTY()
USkeletalMesh* defaultMesh;

UPROPERTY()
UClass* defaultAnimInstance;

Initialized them within PostInitializeComponents():

defaultMesh = Mesh->SkeletalMesh;
defaultAnimInstance = Mesh->GetAnimInstance()->GetClass();

Then I just used these variables as the default pointers. Allowing me to change to external Skeletal Meshes and Animation Instances with SetAnimClass() and SetSkeletalMesh().