What are ACTORs?

I dont understand really much what is actor and what is the porpose of it, ive read the documentation but i still dont understand what can i do with actors and why should i use them.

The documentation said i can synchronize and desynchronize and use them as containers.
Can the actors be used as a class like the Actor class in unreal engine? meaning i can use it to create objects and npcs?

Or what is the porpuse

2 Likes

You can use them to optimize games, using parallel Lua.

Does it only works for muli-threading or can it work with other things.

It can work for other things. Such as being a container or receiving events.

Does it have any use like for npcs and stuff?
like if i want to put an npc character inside the Actor and use a script to run it does it work?

The NPC won’t show up in the visual world, but it will exist.

1 Like

They can be thought of as seperate bins that allow simaltanous code execution. Normally lua is single threaded/serial, which means that all code is ran in sequence, which can cause problem if large computation jobs need to be done, causing your game to lag or freeze.

Actors in combination with some specialized code, allows code to ‘desynchronize’ from the main sequence loop, allowing them to run at the same time as the rest of the game, but not cause freeze ups.

7 Likes

Pretty much what @AC_Starmarine said; they allow code to be run in parallel.

This is another way of saying you can run truly asynchronous code. Instead of using only one thread, you can use a second thread to run tasks simultaneously. It’s good for memory-heavy tasks, like handling NPC movement as you said before. Messages can be sent to actors and received by code on the actor with Actor:SendMessage and Actor:BindToMessage/Actor:BindToMessageParallel. You can connect code in parallel with RBXScriptSignal:ConnectParallel, and cause blocks of code to run in parallel with task.desynchronize().

It’s important to note that code won’t run asynchronously by default when in an actor; you need to use one of the methods to set it.

Also, you also need to be aware of thread safety. Some functions, of Instances for example, aren’t safe to be called in parallel and must be called in serial. You can run code in serial again after it’s been desynchronized with task.synchronize.

1 Like

Good video about actors:

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.