RealDocs

UKismetMathLibrary::Conv_BoolToInt

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticBlueprintPureBlueprintAutocast

Description

Converts a boolean to an integer: false returns 0, true returns 1.

Caveats & Gotchas

  • The result is always exactly 0 or 1 — never any other value. This makes it safe to use in arithmetic (e.g. multiplying a value by the result to conditionally zero it out), which is a common Blueprint optimisation to avoid branch nodes.
  • When used as a BlueprintAutocast in Blueprint, the implicit conversion can obscure logic. An explicit Select or Branch node may be clearer to future readers of the graph.

Signature

static UE_INL_API int32 Conv_BoolToInt(bool InBool)

Parameters

Name Type Description Default
InBool bool The boolean value to convert.

Return Type

int32

Example

Branchless conditional multiply C++
bool bIsActive = GetIsActive();
float SpeedMultiplier = 500.f;
// Apply speed only when active, avoiding a branch
float Speed = SpeedMultiplier * UKismetMathLibrary::Conv_BoolToInt(bIsActive);

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.