C++ crash when using GetBodyInstance() for anything with Skeletal Mesh

Hi guys!

I am having a bit of an issue with Skeletal Meshes when using C++. Basically, I am noticing that whenever I try to access GetBodyInstance() in a Skeletal Mesh, it crashes the editor.

Here is an example line of code:

myMeshActor->GetBodyInstance()->bLockYTranslation = 1;

That line is inside a function that gets called by blueprint and it instantly crashes the editor. Anything I try to access in GetBodyInstance() crashes the editor. Both Visual Studio and Xcode compile it just fine.

Here is some example code I made to try solving this:



UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Meshes”)
USkeletalMeshComponent* myMeshActor = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT(“My_Mesh”));

UFUNCTION(BlueprintCallable, Category = “Testing”)
void setMeshProperties();



static ConstructorHelpers::FObjectFinder<USkeletalMesh> myMeshActor_Visual(TEXT("/Game/Meshes/myMesh"));

void AmyMeshActor::setMeshProperties()
myMeshActor->GetBodyInstance()->bLockYTranslation = 1; //This causes crash


Any idea if I am trying to access it wrong?

I have also tested this issue with a Static Mesh and that does NOT cause a crash. No idea why. Thank you in advance.

Skeletal Meshes unlike all other primitives often have multiple body instances, and each of those has a unique Name. Unless you have a body on the root bone of the mesh, then calling that function will always return null.

Bingo! Did not know that. Can you specify further what you mean though? What do you mean by body on the root bone? I should have mentioned that this is an actor class I am working with, not a character class. And thanks again!

I think I got it figured out but I will post back.

Having some trouble still. I now do have a body on the root bone but it is still returning NULL.