Skip to content

Remote Procedure Calls

Lakatrazz edited this page Jan 18, 2025 · 12 revisions

Remote Procedure Calls are a standard method to allow you to call functions on other people's games. For Fusion, this lets you synchronize events in your mods, such as the beginning of an animation, a sound effect, and more. The marrow integration has multiple scripts that let you take advantage of this functionality.

IMPORTANT

When using RPC Events or Variables, never put them on disabled GameObjects. They only initialize properly on Awake, which requires their GameObject to be enabled. If you try to use an RPC Event that is on a disabled GameObject, it's very likely that you will experience syncing issues!

RPC Event

RPC Event is the most basic form of synchronization. Let's take a look at it in the editor:

RPC Event Script

  • Target
    • You can choose between either Server or Clients. When the event is activated, a message will be sent to the target. Only the server can send messages to the Clients, but anyone can send a message to the Server. Once they receive the message, the "On Event Received" UltEventHolder will activate.
  • Channel
    • You can choose between the Reliable and Unreliable channels. By default the script is Reliable, which means it is guaranteed to be sent. This is good for important events that need to happen, such as an animation trigger. However, it requires extra bandwidth and performance. For events that are not as important, such as particle effects, sounds, or events called every frame, Unreliable is preferable. Unreliable does not guarantee the message will be sent and received.
  • Requires Ownership
    • This mainly applies to RPC Events on spawnable or synced objects. If this is checked, the person invoking the RPC Event will need to have "ownership" of the object in order to send a message. Ownership is usually obtained when the user grabs, hits, or interacts with the object. If the user does not have ownership, the event will not send.
      • If enabled on an object that is not a spawnable or synced object, then the server host has ownership.
  • On Event Received Holder
    • This is a slot for an UltEventHolder, which contains the main logic for the RPC Event. The UltEvent is called on the target's game when another user invokes the RPC Event. If you do not know much about UltEvents, it is recommended to learn the basics first.

Using The Event

In order to activate the event, a user needs to call Invoke on the RPC Event from another script. An example is from an UltEventHolder, as shown here:

Event Invocation

Once invoked, a "bool" will be returned. This is a True or False value indicating whether or not the RPC Event sent the message correctly.

Afterwards, the message will be received on the target's game, and the "On Event Received" UltEventHolder will be called. You can fill this event out to dictate what happens on the target's game.

RPC Variables

RPC Variables are similar to RPC Events, except they allow you to sync state instead of one time events. Let's take a look at an RPC Int:

RPC Int

  • Requires Ownership

    • Similar to RPC Events, this only applies on spawnable or synced objects. This makes it so that only the owner of the object can change the variable.
  • On Variable Changed Holder

    • This UltEventHolder is invoked on all clients when the variable is changed. This allows you to get the latest value of the RPC Variable when it is updated.

Using the Variables

In order to make full use out of RPC Variables, you can call the following functions:

RPC Int Functions

  • GetLatestValue

    • Gets the latest value that the RPC Variable is set to. This allows you to actually use the variable's value in your UltEvents.
  • SetValue

    • Sets the value of the RPC Variable. Returns a bool which is True if the set was successful, and False if not. This action will fail if Requires Ownership is on and the user setting the variable does not have ownership, or if it is off and the user is not the server host.

Currently, there are five RPC Variables:

  • RPC Int
  • RPC Float
  • RPC Bool
  • RPC String
  • RPC Vector3

Once you take full advantage of these, you can create very powerful synced mods without ever exiting the Marrow SDK.

Clone this wiki locally