Hello guys. I’m having a problem to access variables from another class. Here is my code:
PooledObjects.h
#pragma once
#include "CoreMinimal.h"
#include "ObjectPooler.h"
#include "PooledObjects.generated.h"
/**
*
*/
UCLASS()
class PROGRAMMING_TEST_API APooledObjects : public AObjectPooler
{
GENERATED_BODY()
virtual void BeginPlay() override;
public:
APooledObjects();
UPROPERTY()
class UStaticMeshComponent* Nicro;
UPROPERTY(EditAnywhere)
float MinLifespan;
UPROPERTY(EditAnywhere)
float MaxLifespan;
UPROPERTY(EditAnywhere)
AActor* Life;
};
PooledObjects.cpp
void APooledObjects::BeginPlay()
{
Super::BeginPlay();
ASpawner* LifeRef = Cast<ASpawner>(Life);
if (LifeRef)
{
MinLifespan = LifeRef->MinLifetime;
MaxLifespan = LifeRef->MaxLifetime;
SetLifeSpan(FMath::FRandRange(MinLifespan, MaxLifespan));
}
Spawner.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Spawner.generated.h"
UCLASS()
class PROGRAMMING_TEST_API ASpawner : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ASpawner();
virtual void Tick(float DeltaTime) override;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
FORCEINLINE class UBoxComponent* GetCollisionBox() const { return CollisionBox; }
UFUNCTION()
FVector GetRandomPointInVolume();
UPROPERTY(EditAnywhere)
float MinLifetime;
UPROPERTY(EditAnywhere)
float MaxLifetime;
UPROPERTY(EditAnywhere)
AActor * Life;
};
I’m trying to access MinLifespan and MaxLifespan in PooledObjects class from Spawner class so that i could edit the value anytime i want. Please show me what’s wrong with this code. Thank you in advance.