A compiler patch to have networked events with parameters.
- Download and install the project from my VCC Listing
- Inherit from the
NetworkingLibUdonSharpBehaviour
class - Mark the functions you want to be networked with
[NetworkingTarget()]
- Make sure that the person about to make a call is the network owner
Networking.SetOwner(Networking.LocalPlayer, gameObject);
- Call the function with
NetworkingLib_RPC(nameof(function), null, params);
You need to inherit from the NetworkingLibUdonSharpBehaviour class
using UdonSharp;
// I'd recommend using manual sync for your behaviours.
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class InteractExample : NetworkingLibUdonSharpBehaviour {}
To create a networked function, add the NetworkingTarget
attribute to the method.
NetworkingTarget
has 5 different modes.
- All
- AllSelfExclusive
- Master
- Specific
- Local
Each mode describes who the function is called on.
[NetworkingTarget(NetworkingTargetType.AllSelfExclusive)]
private void Ping() {
// Do something
}
Only the network owner of the object will be able to call networked functions
NetworkingLib_RPC(nameof(Ping));
If your NetworkingTarget
was set to Specific
, you'd need to specify the target player in the second parameter.
VRCPlayerApi someplayer = ???;
NetworkingLib_RPC(nameof(Ping), someplayer);
// Create your function like normal
[NetworkingTarget(NetworkingTargetType.AllSelfExclusive)]
private void Ping(string message, float time) {
// Do something
}
private void Start() {
NetworkingLib_RPC(nameof(Ping), null, "Hello there!", 420);
}
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
namespace UdonSharpNetworkingLib.Samples {
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class InteractExample : NetworkingLibUdonSharpBehaviour {
// Set the NetworkingTarget to who should receive the function call.
[NetworkingTarget(NetworkingTargetType.AllSelfExclusive)]
private void Test(string msg, int test, VRCPlayerApi caller, int[] testArray) { // Demo method
Debug.Log($"Triggered! {msg}, num: {test}, caller: ({caller.displayName}, {caller.playerId}), DebugArray: {testArray[0]}, {testArray[1]}, {testArray[2]}");
}
public override void Interact() {
// Make the local player the owner of the GameObject before calling.
Networking.SetOwner(Networking.LocalPlayer, gameObject);
// Make the call
NetworkingLib_RPC(nameof(Test), null, "Hello there!", 69, Networking.LocalPlayer, new[] { 1, 2, 3 });
}
}
}
- Failing to compile if you override the
OnSerialization
functions, Please addAfterNet
orBeforeNet
onto the end of the function names to work around this i.e.public override void DeserializationBeforeNet() { }