So maybe I’m misunderstanding the purpose of Spawn Actor Deferred, but when I set class member variables prior to the constructor, they are all reinitialized to zero in the constructor. Does anyone know why this is?
This is my header
UCLASS()
class MYPROJECT2_API ACProjectile : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
void Init(float,float,float);
UPROPERTY(EditAnywhere)
float radius;
UPROPERTY(EditAnywhere)
float upDir;
UPROPERTY(EditAnywhere)
float sideDir;
ACProjectile();
}`
The following definition IS called before the header and successfully sets the member functions, HOWEVER:
void ACProjectile::Init(float rPass,float nupDir, float nsideDir)
{
ACProjectile::radius=(rPass+2)*100;
ACProjectile::upDir=(nupDir*400)/radius;
ACProjectile::sideDir=(nsideDir*400)/radius;
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::SanitizeFloat(radius));
}
As soon as the constructor is called immediately afterward, the variables are reset to 0.
ACProjectile::ACProjectile()
{
PrimaryActorTick.bCanEverTick = true;
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::SanitizeFloat(ACProjectile::radius));
}
I don’t understand what would cause this behavior. If anyone could help me I would be eternally grateful.