{ }Blueprint → C++

Unreal Engine 5 · Blueprint → C++

Do Once Node in Unreal Engine 5 C++UE Docs

The Blueprint Do Once node runs its output exactly once until reset. In C++ you reproduce it with a bool bHasRun flag guarded by an if (!bHasRun) check.

Blueprint node & C++ equivalent

C++
// .h
bool bHasRun = false;

// .cpp
if (!bHasRun)
{
  bHasRun = true;
  // runs only once until you reset bHasRun
}

What does the Do Once node do?

Do Once lets execution pass through a single time, then blocks every subsequent call until its Reset input fires. It is commonly used to make sure setup logic, a sound cue, or a one-time event triggers only once even though the execution pin may be hit many times.

The C++ equivalent

Declare a bool bHasRun = false; member in your header. In the .cpp, wrap the guarded logic in if (!bHasRun) and set bHasRun = true; as the first thing inside the block. After that the body never runs again until you manually set bHasRun = false;, which is the equivalent of the node's Reset pin.

Common mistakes

A frequent error is using a local variable instead of a class member; a local resets every call and the guard never works. The flag must persist on the object, so declare it in the header. Also remember to set bHasRun = true; inside the if, not after it, or re-entrant calls could slip through.

Frequently asked questions

How do I make code run only once in Unreal C++?+

Add a bool bHasRun = false; member, then guard the logic with if (!bHasRun) { bHasRun = true; ... }. It will run a single time until you reset the flag to false.

How do I reset a Do Once in C++?+

Set the flag back to false, for example bHasRun = false;. This mirrors the Reset input pin on the Blueprint Do Once node.

Related Flow Control nodes

View all Flow Control nodes →