S&box Wiki

Network Callbacks

Network Callbacks

You can get a notification when a [Net] property has changed clientside. This is useful if you want to update something in the UI, or run some other logic when the variable changes on the client without having to poll for changes frequently.

Supported Types

Classes

Entity, NetworkComponent, string

Primitive

bool, byte, sbyte, char, double, float, int, uint, long, ulong, short, ushort

Lists

Any List<T> is supported where T is any of the above classes or primitives with the exception of NetworkComponent, because they cannot be networked in a list.

Usage

Attribute

Add the [OnChangedCallback] attribute to your [Net] property.

Callback Method

Add a method to your Entity or NetworkComponent called On[PropertyName]Changed() where [PropertyName] is the name of your [Net] property.

Example

public partial class Unit : Entity { [Net, Local, OnChangedCallback] public bool IsGathering { get; private set; } private void OnIsGatheringChanged() { if ( IsGathering ) Log.Info( "I am now gathering." ); else Log.Info( "I am no longer gathering." ); } }

Special Pages


Wikis

?

Render Time: 43ms

DB GetPage 26
Generate Html 1
SaveChanges (1) 14
Render Body 0
Render Sidebar 0