GetOwner() cause editor crash

Hello, I’m new in using c++ and UE.
I tried some simple programming but the editor crash.

#include "NewActorComponent.h"
#include "Runtime/Engine/Classes/GameFramework/Actor.h"
    
    UNewActorComponent::UNewActorComponent()
    {
    
    	PrimaryComponentTick.bCanEverTick = true;
    	GetOwner()->GetName();
    }

I knew maybe the output is null so it is crashed,but idk how to expect the error without any crash.

What exactly are you trying to achieve?
I only ask, because you may not actually want an actor component.

In the event that you do need to use an actor component, then take a look at this: AActor::AddOwnedComponent

Using that in the actor the component is attached to, and passing the component into the parameter may just fix your problem, though I can’t be certain without trying it!

How are you adding you component to the actor?
Like this, perhaps?

MyComponent = CreateDefaultSubobject<UNewActorComponent>(TEXT("MyComponentName"));

Taking a bit of a stab in the dark here, but I’m not too familiar with using UActorComponents myself, though I really aught to learn! They behave a little differently to other components though, hence why I would like to know what it is you’re trying to achieve. :wink:

as I said It is only simple programming and then the editor crash.
my goal is to know why it is crashed and prevent it. I’m looking forward to understanding the editor more.