That’s a null(-ish) pointer exception. You haven’t put anything into the variable.
This is how you would usually do this.
In your MyCharacter.h:
UCLASS()
class YOURPROJECT_API AMyCharacter : public AActor
{
GENERATED_BODY()
public:
AMyCharacter();
protected:
virtual void BeginPlay() override;
public:
UFUNCTION(BlueprintCallable)
void GetTraceComponent();
private:
UPROPERTY(VisibleAnywhere)
UTraceComponent* TraceComponent;
};
In your MyCharacter.cpp file:
AMyCharacter::AMyCharacter()
{
// (other initialization code)
TraceComponent = CreateDefaultSubobject<UTraceComponent>(TEXT("TraceComponent"));
}
AMyCharacter::GetTraceComponent()
{
return TraceComponent;
}
In your CameraMovementComponent.cpp:
UCameraMovementComponent::BeginPlay()
{
Super::BeginPlay();
AMyCharacter* MyCharacterOwner = Cast<AMyCharacter>(GetOwner());
UTraceComponent OwnerTraceComponent = MyCharacterOwner->GetTraceComponent();
// Do something with OwnerTraceComponent here, or store it in a member property.
}
(I wrote that in a text editor without trying compiling it, it might have some errors)
Notice that I’m putting the code to get the owner’s component in BeginPlay(). This is important! You should not put any logic into an object’s constructor other than what is necessary to set up the object and its subobjects. Every C++ class gets initialized on engine init to create their CDOs, and at that time they don’t have owners or anything. The game isn’t even playing at that time.
Putting that code at BeginPlay() will ensure that the code happens actually at runtime when you’re playing your game. In your case you should only have PrimaryComponentTick.bCanEverTick = true; in the constructor and move everything else into BeginPlay().