Getting a Crash on Method Call

I’ve created a socket on a mesh I’m using as a special door. I want to get the location of this socket so I can do some maths and make a nice rotation and translation effect. I’ve gone about attempting to get the socket in the following manner but it crashes Unreal soon as it is called:


void UDoorRotator::OpenDoorByAxialRotation() {
	
	USkeletalMeshComponent* DoorMesh = nullptr;
	DoorMesh = Door->FindComponentByClass<USkeletalMeshComponent>();
	FVector DoorPivotPoint = DoorMesh->GetSocketByName("PivotPoint")->GetSocketLocation(DoorMesh);
	UE_LOG(LogTemp, Warning, TEXT("DoorMesh: %s, DoorSocket: %s,  DoorPivotPointLocation: %s"), *DoorMesh->GetName(), *DoorMesh->GetSocketByName("PivotPoint")->GetName(), *DoorPivotPoint.ToString())

}

It could be that I have some dangling pointers in the UE_LOG since I’m not checking if they are null or not. It could also be GetSocketLoction(DoorMesh) since I was not sure what to pass into that method. I don’t understand why I need to pass anything in since I already have the socket but it craps out if I do not give it a reference parameter.

Most of the common crashes are usually “undefined reference” to an object. The easier way to troubleshoot is to uncomment some of the later function statements and work it out line by line.

You should use


*GetNameSafe(TheObject)

, that way you don’t need the pointer dereference (which will crash the engine if it’s nullptr).

Thing is though, you’re doing that LOG entry AFTER dereferencing the ‘Door’ and ‘Door Mesh’ pointers anyway, so if either is invalid, you won’t get that far. In this case, you probably want to use ‘checkf’ instead (see assertions), which will crash the game for you if it’s invalid.