CameraComponent->TransformUpdated.AddThreadSafeSP causes crash


I’m using the delegate provided by USceneComponent “TransformUpdated” in order to retrieve update events fired by a UCameraComponent.
I’m retrieving the camera component already created, then I’m creating a TSharedRef for storing the link to the calling instance.

Then I call for AddThreadSafeSP, and the crash starts.

TSharedRef<UMultipleCamSpringArmComponent, ESPMode::ThreadSafe> sharedPtr = TSharedRef<UMultipleCamSpringArmComponent, ESPMode::ThreadSafe>(this);
ChildCamera->TransformUpdated.AddThreadSafeSP(sharedPtr, &OnChildCameraTransformUpdateHandle);

void UMultipleCamSpringArmComponent::OnChildCameraTransformUpdateHandle(USceneComponent* camera, EUpdateTransformFlags flags, ETeleportType teleportType ) {
	UE_LOG(LogTemp, Log, TEXT("yeee callback"));

Does anybody know why?

I don’t even know how you were able to get that to compile. I always get an unrecognized type indentiyer error on EUpdateTransformFlags even after including Components/ActorComponent.h

You should use either AddUObject, AddUFunction or AddWeakLambda instead of AddThreadSafeSP.

From Unreal Smart Pointer Library | Unreal Engine Documentation

Shared Pointers are not compatible with Unreal objects (UObject and its derived classes). The Engine has a separate memory management system (see Object Handling documentation) for UObject management, and the two systems have no overlap with each other.

1 Like