Is there any way to update the value in a costructor script before spawning an actor.?

I have an actor having its constructor script something like this.

APlanetActor::APlanetActor(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

DistanceFromStar = 5000;

}

But I also have an actorcomponent inside the construction script which has some calculation depending upload the variable DistanceFromStar.

After I spawn the actor, then the construction script would have been executed and I don’t think there would be a way to change the value given to that actorcomponent. So is there a way change ta value of class variable before the construction script has been executed? Like making another default value?

First Why dont you just create a function for that actor which when called sets the value and then actorcomponent does its calculation then ?

I am creating many splinemeshcomponent actors through a for loop so I need to know how many are their total cause I can use PCIP outside the for loop.

I also had this problem, and wrote a fairly detailed forum post about this.

You can always find assets (even outside of the constructor) with StaticLoadObject, e.g.

Cast<UTexture2D>(StaticLoadObject(UTexture2D::StaticClass(), NULL, *(Path)

Ah ok, I see that’s quite a predicament. I’m assuming you’ll be extending classes from this ASplineGeneratingActor for generating specific splines, otherwise there wouldn’t be a problem.

I don’t have the code in front of me at the moment, but I’d suggest looking into whether it’s possible to create default subobjects outside of the constructor, or passing parameters to the constructor via PCIP.

I think this method wont work here. Cause I wont be able to find assets outside constructor. I am thinking of using a static variable now whose value I can change during run time and the static variable is going to have some use in constructor. Let me see if that works.

I don’t want to load something. I want to change variables values before a constructor is called.

e.g. in constructor I got something like this

    ASplineGeneratingActor::ASplineGeneratingActor(const class FPostConstructInitializeProperties& PCIP)
    	: Super(PCIP)
    {
    	int32 NoOfRings = RingData.Num();
    
    	for (int32 i = 0; i < NoOfRings; i++)
    	{
    		FString StringName = "SplineRing" + FString::FromInt(i);
    		FName RingName = FName(*StringName);
    		TSubobjectPtr<USplineComponent> SplineComp = PCIP.CreateDefaultSubobject<USplineComponent>(this, RingName);
.....
.....
.....
}
}

I need to set the RingData array before the constructor is called.