Changing player mesh while in-game C++

In my project, I have a player with a spaceship static mesh set in constructor. What I want to do, is to change player’s ship in shop menu. The idea is that I press a button that calls a function, and that function changes the static mesh depending on the int passed in. But, the problem is that I can’t use ConstructorHelpers outside the constructor, so using a function with a switch causes UE4 to crash. I’m thinking about destroying and respawning player with another mesh, but while destroying player shouldn’t be difficult, I don’t know how to respawn him. And how to respawn him with differen mesh (I’m using Actor component child as inventory and Game instance as a class in which I store certain data when player is destroyed, e.g when I’m changing level). Does anybody have an idea what should to do? I would appreciate any help.

If your ships are doing the same stuff regardless of their visual appearance you can simply change mesh at runtime via
bool UStaticMeshComponent::SetStaticMesh(UStaticMesh* NewMesh)

In constructor script, you need to just declare UStaticMeshComponent and call UStaticMeshComponent::SetStaticMesh in BeginPlay or wherever you want to change it

1 Like