Namespace: fusion
Language: Lua
Type: Extension
Functions and constants for interacting with Photon Fusion
Type: FUNCTION Initialize Fusion.
Parameters
app_id (string)app_version (string)protocol (string) - One of wss, ws, tcp or udpType: FUNCTION Initialize Fusion from game.project settings.
Type: FUNCTION Connect Fusion.
Parameters
user (string) - Player display name, separate from the authentication user id.
auth (table) - Authentication options. Omit or pass nil for anonymous authentication.
Optional fields: type (a fusion.AUTH_TYPE_* constant, defaults to AUTH_TYPE_NONE),
user_id (string), parameters (URL-encoded query string without a leading ?),
and data (POST data: a string or a table with string keys and string, number or
boolean values). An empty table is an empty property map. Nested tables are not
supported. Configure the provider and disable anonymous access in the Photon
dashboard to require authentication.
Type: FUNCTION Disonnect Fusion.
Type: FUNCTION Reconnect Fusion.
Type: FUNCTION Start Fusion sync.
Type: FUNCTION Stop Fusion sync.
Type: FUNCTION Get connection state.
Returns
number - The connection stateType: FUNCTION Get disconnect cause.
Returns
number - The disconnect causeType: FUNCTION Join or create random room.
Parameters
create_room_options (table)matchmaking_options (table)Type: FUNCTION Join random room.
Parameters
matchmaking_options (table)Type: FUNCTION Join room.
Parameters
room_name (string)join_room_options (table)Type: FUNCTION Join or create room.
Parameters
room_name (string)create_room_options (table)join_room_options (table)Type: FUNCTION Create room.
Parameters
room_name (string)create_room_options (table)Type: FUNCTION Leave room.
Parameters
will_come_back (boolean)send_auth_cookie (boolean)Type: FUNCTION Check if Fusion is connected.
Returns
booleanType: FUNCTION Check if Fusion has config and is connected.
Returns
booleanType: FUNCTION
Check if Fusion is started. Fusion is considered started after a call to.
fusion.start() has received a EventOnFusionStart event.
Returns
booleanType: FUNCTION Check if Fusion is in a room.
Returns
booleanType: FUNCTION Enable/disable debugging.
Parameters
enable (boolean)Type: FUNCTION Create a map object.
Parameters
map (number)owner_mode (number)options (table) - Table with properties and replication_mode fields. The
properties field should be a id,property map with script ids and properties to
sync. Replication mode should be one of the established REPLICATION_MODE
constants.
id (string)Type: FUNCTION Create a networked game object. This will spawn a game object in the same. Way as when calling factory.create(). The function will also register the spawned object with Fusion as if manually calling register_object()
Parameters
factory_url (string)position (vector3) - Initial position of created game object
rotation (quat) - Initial rotation of created game object
map (number) - The map to which this object belongs
owner_mode (number) - Owner mode of spawned object
options (table) - Table with properties and replication_mode fields. The
properties field should be a id,property map with script ids and properties to
sync. Replication mode should be one of the established REPLICATION_MODE
constants.Returns
hash - Id of the spawned game objectType: FUNCTION Destroy a networked object.
Parameters
id (string)Type: FUNCTION Create an object.
Parameters
factory_url (string)map (number)owner_mode (number)options (table)id (string)Type: FUNCTION Destroy a previously created object.
Parameters
id (string)Type: FUNCTION Add map.
Parameters
data (string)Returns
number - Map idType: FUNCTION Change map.
Parameters
data (string)Returns
number - Map idType: FUNCTION Remove map.
Parameters
map (number) - Map idType: FUNCTION Check if map is valid.
Parameters
map (number) - Map idReturns
boolean - True if validType: FUNCTION Send an RPC event. Events can be sent to a specific player or all players, and. To a specific object or to all subscribers.
Parameters
target_player (number) - 0 = all, specific PlayerId = targeted
target_object (hash) - Id of game object, nil for broadcast
event (hash)data (table)Returns
booleanType: FUNCTION Subscribe to RPC broadcast event. The events will be delivered as messages.
Parameters
rpc_event (hash) - Event to subscribe to
id (hash) - Subscriber id
Type: FUNCTION Unsubscribe from a subscribed RPC event.
Parameters
rpc_event (hash) - Event to unsubscribe to
id (hash) - Which object should unsubscribe
Type: FUNCTION Set event listener.
Parameters
listener (function)Type: FUNCTION Get the player id of the local client
Returns
number - The player id of the local clientType: FUNCTION Get the player id of the current owner of an object
Parameters
id (string) - Id of the object to get the owner forReturns
number - The player id of the object’s ownerType: FUNCTION Check if this client has authority over a game object. Use this to decide if user input should be handled or not.
Parameters
id (string)Returns
boolean - Returns true if the client has authorityType: FUNCTION Check if an object has an owner
Parameters
id (string) - Id of the objectReturns
boolean - True if the object has an ownerType: FUNCTION Signal desire for the local client to own an object
Parameters
claim_ownership (boolean)id (string) - Id of the object to ownType: FUNCTION Explicitly clear the ownership cooldown
Parameters
id (string) - Id of the object to clear cooldown forType: FUNCTION Respond to a received ownership request
Parameters
object (string) - Id of the object
requester (number) - Requesting player id
granted (boolean) - True if the request is granted
Type: FUNCTION Set the send rate of an object. This decided how much bandwidth to allocate
Parameters
send_rate (number)id (string) - Id of the object to send rate forType: FUNCTION
Set the local send rate divisor for an object. A value of 1 means the object sends every tick (highest rate). A value of 16 means it sends every 16th tick (lowest rate). This is a client-side optimization – the object still exists on all clients but consumes less bandwidth when you are not the active authority.
Parameters
send_rate (number)id (string) - Id of the object to send rate forType: FUNCTION Reset the send rate of an object.
Parameters
id (string) - Id of the object to reset send rate forType: FUNCTION Get player count
Returns
number - Number of playersType: FUNCTION Get if this client is the room’s master
Returns
boolean - True if this client is the room’s masterType: FUNCTION Get round trip time
Returns
number - Round trip time in secondsType: FUNCTION Get the network time
Returns
number - Network timeType: FUNCTION Get raw offset between server time and local time. A positive value means the server clock is ahead of the local clock.
Returns
number - Time diffType: FUNCTION Set global visibility key for an object
Parameters
id (hash) - Object to set global visibility key forType: FUNCTION Set area visibility key for an object
Parameters
key (hash) - Area key
id (hash) - Object to set area visibility key for
Type: FUNCTION Set user visibility key for an object
Parameters
key (hash) - User key
id (hash) - Object to set user visibility key for
Type: FUNCTION Set area visibility keys
Parameters
keys (table) - Area keys to set. Stored as a table of key value pairs (area_key->send_rate)Type: FUNCTION Add a user visibility key to the set of local interest keys.
Parameters
key (hash) - User key to addType: FUNCTION Remove a user visibility key from the set of local interest keys.
Parameters
key (hash) - User key to removeType: VARIABLE OWNERMODE_TRANSACTION
Type: VARIABLE OWNERMODE_PLAYERATTACHED
Type: VARIABLE OWNERMODE_DYNAMIC
Type: VARIABLE OWNERMODE_MASTERCLIENT
Type: VARIABLE OWNERMODE_GAMEGLOBAL
Type: VARIABLE No custom authentication (default).
Type: VARIABLE Custom authentication.
Type: VARIABLE Steam authentication.
Type: VARIABLE Facebook authentication.
Type: VARIABLE Oculus authentication.
Type: VARIABLE PlayStation4 authentication.
Type: VARIABLE Xbox authentication.
Type: VARIABLE Viveport authentication.
Type: VARIABLE NintendoSwitch authentication.
Type: VARIABLE PlayStation5 authentication.
Type: VARIABLE Epic authentication.
Type: VARIABLE FacebookGaming authentication.
Type: VARIABLE STATE_DISCONNECTED
Type: VARIABLE STATE_CONNECTING
Type: VARIABLE STATE_CONNECTED
Type: VARIABLE STATE_JOININGROOM
Type: VARIABLE STATE_INROOM
Type: VARIABLE STATE_LEAVINGROOM
Type: VARIABLE STATE_DISCONNECTING
Type: VARIABLE DISCONNECT_CAUSE_NONE
Type: VARIABLE DISCONNECT_CAUSE_DISCONNECTBYSERVERUSERLIMIT
Type: VARIABLE DISCONNECT_CAUSE_EXCEPTIONONCONNECT
Type: VARIABLE DISCONNECT_CAUSE_DISCONNECTBYSERVER
Type: VARIABLE DISCONNECT_CAUSE_DISCONNECTBYSERVERLOGIC
Type: VARIABLE DISCONNECT_CAUSE_TIMEOUTDISCONNECT
Type: VARIABLE DISCONNECT_CAUSE_EXCEPTION
Type: VARIABLE DISCONNECT_CAUSE_INVALIDAUTHENTICATION
Type: VARIABLE DISCONNECT_CAUSE_MAXCCUREACHED
Type: VARIABLE DISCONNECT_CAUSE_INVALIDREGION
Type: VARIABLE DISCONNECT_CAUSE_OPERATIONNOTALLOWEDINCURRENTSTATE
Type: VARIABLE DISCONNECT_CAUSE_CUSTOMAUTHENTICATIONFAILED
Type: VARIABLE DISCONNECT_CAUSE_CLIENTVERSIONTOOOLD
Type: VARIABLE DISCONNECT_CAUSE_CLIENTVERSIONINVALID
Type: VARIABLE DISCONNECT_CAUSE_DASHBOARDVERSIONINVALID
Type: VARIABLE DISCONNECT_CAUSE_AUTHENTICATIONTICKETEXPIRED
Type: VARIABLE DISCONNECT_CAUSE_DISCONNECTBYOPERATIONLIMIT
Type: VARIABLE MASTER_CLIENT_PLAYER_ID
Type: VARIABLE PLUGIN_PLAYER_ID
Type: VARIABLE OBJECT_OWNER_PLAYER_ID
Type: VARIABLE REPLICATION_MODE_NONE
Type: VARIABLE REPLICATION_MODE_AUTO
Type: VARIABLE FORCED_DISCONNECT_REASON_GENERIC
Type: VARIABLE FORCED_DISCONNECT_REASON_PROTOCOLINCOMPATIBLE
Type: VARIABLE FORCED_DISCONNECT_REASON_ROOMVERSIONMISMATCH
Type: VARIABLE EVENT_OBJECT_READY
Type: VARIABLE EVENT_SUB_OBJECT_CREATED
Type: VARIABLE EVENT_OBJECT_DESTROYED
Type: VARIABLE EVENT_SUB_OBJECT_DESTROYED
Type: VARIABLE EVENT_OBJECT_FORCE_ALIVE
Type: VARIABLE EVENT_SUB_OBJECT_FORCE_ALIVE
Type: VARIABLE EVENT_OBJECT_OWNER_CHANGED
Type: VARIABLE EVENT_PREDICTION_OVERRIDE
Type: VARIABLE EVENT_LOBBY_STATS
Type: VARIABLE EVENT_ROOM_JOINED
Type: VARIABLE EVENT_ROOM_LEFT
Type: VARIABLE EVENT_RPC
Type: VARIABLE EVENT_MAP_CHANGE
Type: VARIABLE EVENT_DESTROYED_MAP_ACTOR
Type: VARIABLE EVENT_INTEREST_ENTER
Type: VARIABLE EVENT_INTEREST_EXIT
Type: VARIABLE EVENT_FORCED_DISCONNECT
Type: VARIABLE EVENT_FUSION_START
Type: VARIABLE EVENT_CONNECTED
Type: VARIABLE EVENT_DISCONNECTED
Type: VARIABLE EVENT_DEFOLD_LOG_EVENT