Skip to main content

Linking Origin to the ObjectPool

Now when a player joins the world, they should be assigned a station object automatically. Although, the system we previously made isn't linked to the assigned object. We need to update the Origin's program to handle getting the object assigned to the local player. The CyanPlayerObjectPool has a notification system that allows an udon program to listen to specific events. We will make the Origin the pool listener. Drag the pool object into the PlayerObjectAssigner's listener field.

In the Origin program, add a new event called "_OnLocalPlayerAssigned". This will automatically be called by the pool when the local player is assigned an object. In the event itself, we need to get this assigned object. You can do this by sending the "_GetPlayerPooledUdonEvent" event to the player pool. Note that the event name is different if you are using UdonSharp.

LocalPlayerAssigned UdonGraphLocalPlayerAssigned UdonSharpLocalPlayerAssigned CyanTrigger

One issue with working with CyanPlayerObjectPool is that assigning variables to the pool object can be tedious. In the previous system, the Origin was set as a public variable. This now needs to be set for all pool objects. You can do it manually by clicking on each object and assigning it, or we can take advantage of the object pool listener methods and assign it in Udon directly.

To do this, add a new public UdonBehaviour variable named "playerAssignedPoolObject" and create a new event called "_OnPlayerAssigned". Inside this event, call SetProgramVariable on the UdonBehaviour to set the origin transform to this object's transform.

OnPlayerAssigned UdonGraphOnPlayerAssigned UdonSharpOnPlayerAssigned CyanTrigger

At this point, the system should be fully usable. Upload a build and join it with multiple clients to test it out.

Multiple Players Wall Walking