PostBeginPlay

From ZDoom Wiki
Jump to navigation Jump to search


Thinker

virtual void PostBeginPlay()

Usage

A virtual function used by the Thinker class (which includes actors). It's called right after BeginPlay and before the first Tick call. For actors, it happens after the actor has already spawned, but before they actually enter their Spawn state.

This function can be overridden to perform one-time setups, like giving local variables a value, setting flags and such, before any of that data gets overridden or referenced in the states.

WARNING: Due to the way GZDoom handles calling a state's function (a state change immediately calls the function attached to the new state), there is no guarantee that PostBeginPlay runs before any state, especially in weapons/inventory items. Timing-critical operations should not rely on this assumption, and would be better deferred for a few tics into the weapon/inventory's existence.

Error.gif
Warning: On PlayerPawn actors, weird quirks can occur if voodoo dolls are present and PostBeginPlay is overridden without proper handling, because both the original PlayerPawn and its voodoo doll will execute the override at the same time. See the Voodoo doll page for information on how to check if a PlayerPawn is a voodoo doll or not.


Examples

This version of the Zombieman defines an integer field foo which is set to 15 as soon as this actor spawns:

class MyZombieman : Zombieman
{
	int foo;

	override void PostBeginPlay()
	{
		Super.PostBeginPlay();
		foo = 15;
	}
}