Setting Skeletal Mesh through C++

BP Asset Link

I assume your main character class has a blueprint in the Editor that you are using with game mode to spawn your character.

If you do indeed have a blueprint of the related class, you can just add the asset link in your .h file directly rather than hardcoding the lookup, which can and frequently does fail during packaging.

Step 1:



UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Assets")
USkeletalMesh* AlternateMeshAsset;


then in cpp file

Step 2:
if()pollllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll <~~~ cat on keyboard



if(AlternateMeshAsset)
{
  PlayerMesh->SetSkeletalMesh(AlternateMeshAsset);
}


Step 3:
Then you set the asset ptr in the Editor and you’re done!

I am a huge fan of doing stuff purely in C++, however asset references are one thing I always do via the editor because hardcoded asset references can break during packaging and make it a pain to move/rename c++ referenced assets.

:slight_smile:

Rama

4 Likes