Quick start guide
This guide provides a sample to help you quickly learn how to use the multiplayer API. The example creates a networked visual effect (VFX) that can be triggered by pressing the "J" key, with the effect being synchronized across all clients.
- Coding features may differ between game kits. To learn more about scripting in other kits, refer to Party Coding and Horror Coding.
- Lua scripting functionality is available in Horror Game Kit starting from version 1.5.0. If your project is based on Horror Game Kit 1.0, we recommend upgrading to a later version to access this feature.
Prerequisites
- Download and install Visual Studio Code and set it as an external editor in YAHAHA Studio.
- Configure the debugger in Visual Studio Code and attach it to YAHAHA Studio.
- Create a horror Project. For more information, see Creating your first project.
Create a new script on a VFX
In YAHAHA Studio, you create a script for a specific object and then redirect it to an external editor to create gameplay logic.
-
Add a VFX from Asset Library and place it into your scene. For this example, we will use an effect named "Explosion."

-
Enable the VFX's networking by clicking Enable networking in the Properties window, or by right-clicking the VFX in Scene Explorer and selecting Enable Networking. Once enabled, the state of the VFX will synchronize across all clients connected to the server.
-
Create a Lua script on the VFX:
- Select the VFX.
- Click the Add Lua Script button in the Properties window.
- Click New Lua script and enter a name for the script, such as "NetworkVFX".
Script runtime logic for the VFX
Once you enter a script name, two Lua scripts are generated and automatically opened in Visual Studio Code:
-
{ComponentName}.editor.luais used to define the component fields in the Properties window. -
{ComponentName}.luais used to implement the runtime logic.
Open the NetworkVFX.lua script and add runtime logic to it. This example manages a networked visual effect that can be triggered by pressing the "J" key, incorporating both client-side and server-side logic:
- On the client, when the script starts, it subscribes to the "PlayVFX" message to play the visual effect using the ParticleSystem component upon receiving the message. When the "J" key is pressed, it sends an "OnPlayVFXKeyDown" message to the server.
- On the server side, the script subscribes to the "OnPlayVFXKeyDown" message from clients and broadcasts a "PlayVFX" message to all connected clients to trigger the visual effect.
----------- Client -----------
local function OnStart()
if script.IsClient() then
--Listen for the play effect message on the client
script.SubscribeAsync("PlayVFX", function()
--Play the visual effect
local vfx = script.gameObject:GetComponent(typeof(UnityEngine.ParticleSystem))
if vfx ~= nil then
vfx:Simulate(0,true,true)
vfx:Play(true)
end
end)
end
----------- Server -----------
if script.IsServer() then
--Listen for the key down event sent from the client on the server
script.SubscribeAsync("OnPlayVFXKeyDown", function()
--Broadcast to all clients to play the effect
script.PublishAsyncServerToClients("PlayVFX")
end)
end
end
script.OnStart(OnStart)
local function OnUpdate()
--Press the keyboard key, here it's the "J" key
if UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.J) then
if script.IsServer() then
--Already on the server, so directly notify all clients to play the effect
script.PublishAsyncServerToClients("PlayVFX")
elseif script.IsClient() then
--Send the key press message to the server
script.PublishAsyncClientToServer("OnPlayVFXKeyDown")
end
end
end
script.OnUpdate(OnUpdate)
Now, save the script before continuing with the following steps.
Debug and test your script
To avoid problems during the code compilation process, YAHAHA Studio recommends using the debugging extension EmmyLua. For more details, see Debugging Lua scripts.
Launch your custom script in YAHAHA Studio
The Network VFX (Script) component, which responds to key presses, is now ready to be executed in YAHAHA Studio.
-
Enter Play Mode: Click the Play button to enter the Play Mode.

-
Verify the Logic: Ensure the capsule object follows the logic configuration of the Movespeed component for motion.

On your own
Using what you have learned throughout this Quick Start guide, try to do the following:
- YAHAHA Studio uses Lua language. Learn more about the Lua language by visiting Scripting Language Reference.
- Learn more about the field types of components and how to use it: