| Home Page | Recent Changes

Latent Function

Latent functions are special functions which are expected to take some time for execution, not because they use the processor heavily, but because they contain intentional slow-downs (for example if they have to wait for a certain in-game event to occur before they can continue)

Latent functions can only be used in state code (i.e. in labels outside of functions within states. See ScriptedPawn's script for excellent examples), which is not contained in an Iterator (ForEach) loop. They will cause script execution within the state to pause until some condition is met. All other functions and states in other classes will continue to execute normally.

Technical mojo from UnrealScript Language Reference:

Functions which require game-time to pass are called "latent functions". Some examples of latent functions include "Sleep", "FinishAnim", and "MoveTo". Latent functions in UnrealScript may only be called from code within a state, not from code within a function.

While an actor is executing a latent function, that actor's state execution doesn't continue until the latent function completes. However, other actors, or the VM, may call functions within the actor. The net result is that all UnrealScript functions can be called at any time, even while latent functions are pending.

and also

It is important to note that in Unreal, because the user can save the game at any time, the state of all actors, including their script execution state, can be saved at any time where all actors are at their lowest possible stack level. This persistence requirement is the reason behind the limitation that latent functions may only be called from state code: state code executes at the lowest possible stack level, and thus can be serialized easily. Function code may exist at any stack level, and could have (for example) C++ native functions below it on the stack, which is clearly not a situation which one could save on disk and later restore.

Latent functions require some time to be executed. Typical examples are Sleep which waits for the specified amount of time before returning and FinishAnim which returns when the current animation has finished.

Latent functions can only be called from state code or from other latent functions. Latent functions have to be native.

While you cannot define new latent functions, it is possible to pull a similar effect:

While (!SomeConditionIsMet()) //Pause until this function returns true
  Sleep(0.0);

Lists

Related Topics


Tarquin: Needs some more info. Is there documentation for the actual functions such as Sleep()?

Wormbo: In UT2003 there are only three classes with a few latent functions (Actor, Controller and AIController), so we could as well list and describe them here. Unreal and UT have only two classes with latent functions (Actor (UT) and Pawn (UT)).

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In