Actor
An Actor is a container for code that can be safely split into its own thread.
| Memory category | BaseParts |
|---|
Member index 3
Description
An Actor is a container for code that can be safely split into its own thread using task.desynchronize(). It should also contain the instances used by its scripts.
To learn more about using multiple Actors to optimize script performance, see Parallel Luau.
Notes
- Each
Actorruns in its own Luau VM. ModuleScripts required by anActorare not shared or cached acrossActorsor with the main thread. Each VM executes its own copy of the module, so module-level state is isolated perActor. Design accordingly if your modules hold state you intend to share. script:GetActor()returnsnilwhen called from a ModuleScript unless theModuleScriptis a descendant of theActor.ModuleScriptsstored elsewhere (for example, ReplicatedStorage) and required by anActorare not considered descendants of theActor.
History 9
- 693 Change MemoryCategory of Actor from PhysicsParts to BaseParts
- 573 Change ReturnType of SendMessage from void to null
- 570 Change Parameters of SendMessage from (name: string, message: Tuple) to (topic: string, message: Tuple)
- 570 Change Parameters of BindToMessageParallel from (name: string, function: Function) to (topic: string, function: Function)
- 570 Change Parameters of BindToMessage from (name: string, function: Function) to (topic: string, function: Function)
- 568 Add SendMessage
- 568 Add BindToMessageParallel
- 568 Add BindToMessage
- 455 Add Actor
Members 3
BindToMessage
| Parameters (2) | ||
|---|---|---|
| topic | string | |
| function | Function | |
| Returns (1) | ||
| RBXScriptConnection | ||
This method is used to bind a Luau callback to a message with the specified topic. When a message is sent (using SendMessage()) to the topic specified the provided callback will be called in a serial execution context.
Multiple Luau callbacks may be bound to a single actor and even to a single message topic.
Note: Only the scripts which are descendants of an Actor may bind to its messages.
1 2 3 4 5 6 7 | |
| Thread safety | Safe |
|---|
History 2
- 570 Change Parameters of BindToMessage from (name: string, function: Function) to (topic: string, function: Function)
- 568 Add BindToMessage
BindToMessageParallel
| Parameters (2) | ||
|---|---|---|
| topic | string | |
| function | Function | |
| Returns (1) | ||
| RBXScriptConnection | ||
This method is used to bind a Luau callback to a message with the specified topic. When a message is sent (using SendMessage()) to the topic specified the provided callback will be called in a parallel execution context.
Multiple Luau callbacks may be bound to a single actor and even to a single message topic.
Note: Only the scripts which are descendants of an Actor may bind to its messages.
1 2 3 4 5 6 7 | |
| Thread safety | Safe |
|---|
History 2
- 570 Change Parameters of BindToMessageParallel from (name: string, function: Function) to (topic: string, function: Function)
- 568 Add BindToMessageParallel
SendMessage
| Parameters (2) | ||
|---|---|---|
| topic | string | |
| Returns (1) | ||
| null | ||
Sends a message to an Actor. Messages are sent asynchronously, so the sender will not block or yield when calling the SendMessage() method.
Since a single Actor may receive different kinds of messages, a topic
parameter is used to distinguish between various kinds of messages.
See BindToMessage() for details on receiving a message sent using SendMessage().
Note that message arguments are passed by copy across Luau VM boundaries, not by reference. Sending large tables incurs a full copy on each call. Functions are bound to a specific VM and cannot be passed in messages.
1 2 | |
| Thread safety | Safe |
|---|
History 3
- 573 Change ReturnType of SendMessage from void to null
- 570 Change Parameters of SendMessage from (name: string, message: Tuple) to (topic: string, message: Tuple)
- 568 Add SendMessage