I’m UE4 and C ++ beginner.
I want to refer to variables of other classes, but when UE4 is played, I got a error that the corresponding reference pointer is null.
In the program, certainly it looks like there is nothing set in the pointer to refer to variable of another class.
So I want to write code in the constructor to set it to a pointer to refer to.
I describe the source file to be referred to below.
The referred side is simply described as a normal member variable.
UPROPERTY (EditAnywhere, category = “Countdown”)
int32 CountdownTime;
Reference side
AMyActor :: Tick (float DeltaTime)
if (Countdown-> CountdownTime <1) {
;
}
I refer to member variables of other classes, but I get error that Countdown is null.
Certainly Countdown has not been set, so I’m trying to set it in the constructor.
Please let me tell.
MyActor.h
UCLASS()
class HOWTO_VTE_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor’s properties
AMyActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere)
class ACountdown* Countdown;
};
I thought i had an answer to your problem, but it was just some BS… i just think that these two sentences in red in your MyActor.cpp file will bear no result… so Sorry.
I think Countdown instance is made by drag & drop into lebel editor screen.
I want to get that Countdown instance pointer.
The following line will create a new instance of the Acountdown class.
// Countdown = NewObject<ACountdown>();
Not so, I want a pointer to the object instantiated by UE4 now.
Is there function to get instance name from class name.
And, I get pointer from an instance name.
But I do’nt know such a function.