C++ Get Location of another Actor

Hi,

i have 2 Actors, AMYActor and AMyHunter

MyHunter.h:

UPROPERTY()
	AMyActor* aTarget;

MyHunter.cpp:

            vTargetLocation = aTarget->GetActorLocation();

If i try to use vTargetLocation.Z for instance, the UE Editor crashes to desktop.
Testing a bit, i assume, that aTarget is not existing at all.

So here is the question:

How to get the Actor-Location of “AMyActor” Class in “MyHunter.cpp/MyHunter.h” ?

aTarget has to be assigned to something before you try to get its location. The UPROPERTY statement you listed is empty, so how are you setting aTarget to something in the game?

Hi rantrod,

thanks for your answer.

Which UPROPRTY statement would make sense here to get access to the ActorLocation of AMyActor ?

AMyActor is a class, not an instance. You can only get the location of an instance of a class in the game. Normally you write something like

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="MyVars")
AMyActor *aTarget;

Then in the editor you click on an instance of your AHunter class, then go to ‘Details’, find the ‘aTarget’ parameter under the category ‘MyVars’ and set it to an existing instance of AMyActor class.

Have you done the Blueprint tutorials?