im getting a error and i bet its simple and easy to solve but i cant figure out why its not working. The ActorDistance is a float variable declared alright in the header file, PlayerCharacter is UPROPERTY same has SpotlightPicker, GetDistanceTo is a function made already by epic. I want to give inside GetDistanceTo arguments AActor* PlayerCharacter and OtherActor give it SpotlightPicker.
Everything is ok only the OtherActor has a redline under it and it says “Identifier “OtherActor” is undefined”.
/** Returns the distance from this Actor to OtherActor. */
UFUNCTION(BlueprintCallable, Category = "Utilities|Transformation")
float GetDistanceTo(const AActor* OtherActor) const;
/** Returns the distance from this Actor to OtherActor. */
UFUNCTION(BlueprintCallable, Category = "Utilities|Transformation")
float GetDistanceTo(const AActor* OtherActor) const;
ActorDistance = GetDistanceTo(this->PlayerCharacter, OtherActor->SpotlightPicker);
GetDistanceTo function need only one input parameter which is an actor float
but when you try to call this function you filled with 2 actor (2 parameter) actually…
You need modify the function declaration in this way:
The way its written is :
/** Returns the distance from this Actor to OtherActor. /
UFUNCTION(BlueprintCallable, Category = “Utilities|Transformation”)
float GetDistanceTo(const AActor OtherActor) const;
I dont really want to modify, i could. But dont want to since thats how epic wrote it. And i cant just leave it with 1 argument since i dont want it to be self target.
@Atheist91 I can see how that work but now im getting a error on OtherActor. It says “identifier “OtherActor” is undefined” since its a const. How can it be fixed i tired using ‘const_cast’ but it didnt work.
I’m not sure how your code exactly look like so it’s kind of hard to give you precise answer. However ‘OtherActor->SpotlightPicker’ should be replaced with your variable containing an actor your want to measure distance to.
The error itself doesn’t seem to have anything to do with constness. It simply cannot find variable called OtherActor in your code.
#include "VLDVisual.h"
#include "Kismet/KismetMathLibrary.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Engine/Engine.h"
// Sets default values
AVLDVisual::AVLDVisual()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
FloatMath_ScaleAndSphere = Scale * DefaultSphereRadius;
ActorsDistance = PlayerCharacter->GetDistanceTo(OtherActor->SpotLightPicker);
}
// Called when the game starts or when spawned
void AVLDVisual::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AVLDVisual::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}