How to Enable Sub-Components at Run-Time

Hi All,

I attached rain,snow and fog onto my blueprint and i disabled them. How can i enable them at run-time with C++?

There are two things I can suggest. First use FindComponentByClass as the example below shows:

UFloatingPawnMovement* pawnMovement = FindComponentByClass<UFloatingPawnMovement>();
if (pawnMovement)
{
    pawnMovement->MaxSpeed = maxSpeed;
    pawnMovement->Acceleration = acceleration;
    pawnMovement->Deceleration = deceleration;
    pawnMovement->TurningBoost = turningBoost;
}

Second, the effects may require a little more manipulation as shown below:

TArray<UParticleSystemComponent*> theEffects;
GetComponents(theEffects);
int32 effectCount = theEffects.Num();

for (int32 y = 0; y < effectCount; y++)
{
    // if you just want to activate the effect
    theEffects[y]->Activate();

    // if you want to activate an effect by name
    if (theEffects[y]->GetName().Compare(particleSystemName) == 0)
    {
        theEffects[y]->Activate();
    }
}

Thanks for your advice.It works