RealDocs

UActorComponent::ToggleActive

function Engine Blueprint Since 4.0
#include "Components/ActorComponent.h"
Access: public Specifiers: virtualUFUNCTIONBlueprintCallable

Description

Flips the component's active state — activates it if currently inactive, deactivates it if currently active. Useful for one-liner toggle bindings in Blueprint or input actions.

Caveats & Gotchas

  • Implemented as SetActive(!IsActive()) — respects all virtual ShouldActivate() checks. If ShouldActivate() returns false and the component is inactive, calling ToggleActive() will not activate it.
  • Marked UnsafeDuringActorConstruction — not safe to call during construction scripts.
  • Since this calls through Activate/Deactivate, all delegate broadcasts (OnComponentActivated, OnComponentDeactivated) fire normally. Do not confuse a no-op toggle (blocked by ShouldActivate) with a silent failure — check IsActive() afterwards if the state matters.

Signature

UFUNCTION(BlueprintCallable, Category="Components|Activation", meta=(UnsafeDuringActorConstruction="true"))
ENGINE_API virtual void ToggleActive();

Return Type

void

Example

Toggle component on key press C++
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);
    PlayerInputComponent->BindAction("ToggleLight", IE_Pressed, this, &AMyCharacter::OnToggleLight);
}

void AMyCharacter::OnToggleLight()
{
    if (PointLightComponent)
    {
        PointLightComponent->ToggleActive();
    }
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.