I’m playing around with the third person C++ demo project, and trying to get a reference to the ThirdPersonCharacter BP’s skeletal mesh, so I can run AttachTo:
UMNHitbox::UMNHitbox(){
sockSphere = CreateDefaultSubobject<UStaticMeshComponent>(FName(TEXT("TestSphere")));
ACharacter* myCharacter = (ACharacter*)this->GetOwner();
if (myCharacter != nullptr)
{
if (myCharacter->GetMesh() != nullptr)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "GetMesh != nullptr!");
sockSphere->AttachTo(myCharacter->GetMesh(), "RightHandHB_Socket");
}
}
}
This looks right to me, but GetMesh() returns null every time I run it- I’ve been poring over this, but I can’t see where I’m fudging up. The only line I can think of that might be explicitly wrong is the cast, as I mess up casting syntax a lot- is there another obvious problem with my implementation?