| Home Page | Recent Changes | Preferences

# Simulated Function

A simulated function is a function in an Actor-derived class that can be called on a client in a network game. (Consequently, functions that aren't simulated can not be called on clients in a network game.)

There are non-simulated functions which can be called from the client owning that actor. See `ROLE_AutonomousProxy` in Role.

## Definition

As stated on the Function Syntax page simulated functions can be executed on clients.

Well, the more correct definition might be that simulated functions can be executed if the Actor's Role (not RemoteRole!) on the client or server the function should be executed on is either ROLE_SimulatedProxy, ROLE_AutonomousProxy or ROLE_Authority. (`Role >= ROLE_SimulatedProxy`, i.e. not ROLE_None or ROLE_DumbProxy)

## Executing Simulated Functions

So simulated functions can be executed it the actor's Role is greater than or equal to ROLE_SimulatedProxy. However, being able to execute a function doesn't mean it will be executed. Function calls always stay on the same machine unless there's a valid replication statement for the function. In that case the function will only be executed on the machine the function call was replicated to.

Ok, what does that mean? Basically you have two ways of executing a simulated function client-side:

1. Call it from another client-side function. PostBeginPlay, Tick or HitWall are good candidates for this. Beware of simulated Timer functions, they will only be executed if SetTimer was actually executed on that machine, i.e. if you set the timer on the server, then Timer will only be executed on the server. Server and client have independant timers.
2. Replicate the function call from the server to the client. Note that replicated functions can only be replicated to a single machine, either from any client to the server or from the server to the client of the player owning this actor.

## Simulated States

Now that you (hopefully) are able to execute functions client-side, we can go into client-side states. Calling GotoState will only change the state on that single machine. All other machines in the game are not affected.

You can enter any state on the client (`Role == ROLE_SimulatedProxy`) and execute its (simulated) functions, but state code will only be executed if the state itself is declared with the `simulated` keyword as well.

## Related Topics

- UnrealScript
  - Replication
  - Role and RemoteRole
  - Replicated Function
  - Function Syntax
  - State

Foxpaw: I have a few questions about simulated functions:

- If you declare an "entry point" as simulated, will it get called on all clients? For instance, say I declare Tick as simulated.. does every client tick on it's own based on it's own framerate, or does the server have to replicate the tick function?
- If entry points are simulated automatically without being replicated, what will happen if I set up a replication statement for that function? Will it be run twice, or does the engine recognize the function in the replication statement and thus run it only once? If so, is it the replicated or local version that gets run?
- Variables are replicated only if they have been changed.. if a variable is changed in a simulated function is it still considered changed or does the engine assume that the client changed it itself and thus it will still be in sync?
- As I understand it, simulated functions can only call other simulated functions unless they are the authority version. If a simulated function (non-authority version) calls a non-simulated function, does the client simply ignore the call and proceed, or does it replicate the function to the server, wait for a response, then continue the function once the server has returned something?
- If a superclass has a non-simulated function, and I override it and declare it as simulated, is it simulated or non-simulated? Or does the stuff I wrote in the override function simulate but not the Super.Function call? Or does the simulated call override the previous non-simulated call and force the simulated behaviour all the way up the class tree? What if a simulated function is overridden but the overridden version doesn't use the simulated keyword. (it is declared as non-simulated) Will the Super.Function still simulate instead of the overridden function?

Mr Evil: I have a few answers about simulated functions:

- They are automatically simulated. They are called on the client automatically, not replicated, as a quick experiment will show the bandwidth usage does not change if you simulate Tick.
- You can't set up a replication statement for them, since you can't replicate anything from a superclass, but have to have the replication statement in the class in which the function/variable is declared.
- The engine knows nothing about what variables are being changed on the client in simulated functions, thus it goes ahead and replicates changed variables regardless of their client-side values.
- Calls to non-simulated functions are simply ignored in this case.
- You can simulate functions that are not simulated in a superclass if you wish, but calls to super.blah() will not be simulated (I think).

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In