Skip to content

Part 4. RPC Buttons

rvIceBreaker edited this page May 21, 2022 · 1 revision

In this guide we'll cover RPC Buttons and how to implement RPC calls from your mod's settings page.

About RPC Buttons

The RPC Button control is a button that will can trigger code in your Mod Controller when clicked.

RPC Buttons can be marked as server-side or client side, and ModConfig will handle the RPC/Replication for you.

When to use RPC Buttons

RPC Buttons can be useful for various functionality you wish to expose to players; any administrative or maintenance task can be tied to an RPC Button, which gives you the control to allow admins or players to trigger code in your mod.

Some examples could be

  • Clearing internal data in your mod
  • Resetting or reinitializing actors or classes
  • Manually triggering update code to refresh data

Client-Side RPC Button

We'll start off with a client-side RPC button.

  1. Open the GetModSettings function in your mod controller
  2. Add an Add Setting RPCButton node
  3. Set the Name field, make note that we'll need it later
  4. Set the Label Text and Tooltip Text as you feel is necessary
  5. Use Mod Append Setting as usual to add the RPC Button to the settings object

Now we have an RPC Button as part of our list of settings. We can capture the RPC trigger by adding a Mod RPCClient Event to an event graph in your Mod Controller.

  1. Add a Mod RPCClient Event
  2. Add a VerifyCaller node, and link the Calling Object pin to the Caller pin
  3. Add a Setting RPC node and link the RPC Name pin to the RPC Name Input pin
  4. Enter the RPC Name you created above into the RPC Name pin
  5. Connect a function of your choosing (or a block of code on the event graph) to the Is RPC pin

When a user clicks your RPC Button control in the ModConfig page, the code you connected to the Is RPC pin will be executed on the client.

Server-side RPC Button

Server-side RPC calls are similar to other server-side controls in ModConfig.

  1. Open the GetModSettings function in your mod controller
  2. Add an Add Setting RPCButton node
  3. Set the Name field, make note that we'll need it later
  4. Set the Label Text and Tooltip Text as you feel is necessary
  5. Add a Setting Mark Server Side node and connect the Setting Object pin to the Setting Field pin
  6. Use Mod Append Setting as usual

Now we have an RPC button marked as server-side. This means two things for RPC button controls

  • The RPC button will only be visible to admins
  • The RPC code will automatically trigger on the server when the button is clicked

Now with the RPC Button marked as server-side and added to our settings page, we can capture the RPC call in the Mod Controller. This process is similar to the client-side version above

  1. Add a Mod RPCServer Event
  2. Add a VerifyCaller node, and link the Calling Object pin to the Caller pin
  3. Add a Setting RPC node and link the RPC Name pin to the RPC Name Input pin
  4. Enter the RPC Name you created above into the RPC Name pin
  5. Connect a function of your choosing (or a block of code on the event graph) to the Is RPC pin

As said above, when a user clicks your RPC Button control in the ModConfig page, the code you connected to the Is RPC pin will be executed on the server now. You can use this to replicate back to all clients or run authoritative code.

Clone this wiki locally