on_actor_state_created
Event fired when an Actor Lua state becomes available.
Syntax
on_actor_state_created: VoltSignalDescription
on_actor_state_created is a global VoltSignal that passes the related Actor to each callback.
Event Arguments
| Argument | Type | Description |
|---|---|---|
actor | Actor | The Actor instance whose state was created |
Example
on_actor_state_created:Connect(function(actor)
print("New actor state created:", actor:GetFullName())
-- Get the state for this actor
local state = getluastate(actor)
print("State ID:", state.Id)
end)Setup Hooks on New States
on_actor_state_created:Connect(function(actor)
local state = getluastate(actor)
-- Execute setup code on the new state
state:Execute([[
-- This runs before any scripts execute on the actor
print("Actor state initialized!")
]])
end)With Communication Channel
local id, channel = create_comm_channel()
channel.Event:Connect(function(actorName)
print("Actor state ready:", actorName)
end)
on_actor_state_created:Connect(function(actor)
local state = getluastate(actor)
state:Execute([[
local channelId = ...
local channel = get_comm_channel(channelId)
channel:Fire(script:GetFullName())
]], id)
end)Notes
- Fires when an Actor state becomes available
- The callback receives the Actor instance
Related Functions
getluastate- Get LuaStateProxy for an actorgetactorstates- Get all active LuaStateProxy objects