RealDocs

AActor::SetCanBeDamaged

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public

Description

Sets whether this actor can receive damage. Disabling this will cause the built-in `TakeDamage` to return 0 without processing damage events.

Caveats & Gotchas

  • Prefer setting `bCanBeDamaged = false` in the constructor for actors that are permanently invincible, as that avoids the overhead of any early-out check at runtime. Use `SetCanBeDamaged` only when the state needs to change dynamically.
  • This setter exists because `bCanBeDamaged` is private; the engine comment explicitly states it may be made private in future versions, so direct property access should be avoided.

Signature

ENGINE_API void SetCanBeDamaged(bool bInCanBeDamaged)

Parameters

Name Type Description Default
bInCanBeDamaged bool New value for the bCanBeDamaged flag.

Return Type

void

Example

Temporarily make a boss invulnerable C++
void ABossActor::EnterInvinciblePhase()
{
    SetCanBeDamaged(false);
    GetWorldTimerManager().SetTimer(InvincibleTimer, this,
        &ABossActor::ExitInvinciblePhase, 3.0f, false);
}

void ABossActor::ExitInvinciblePhase()
{
    SetCanBeDamaged(true);
}

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.