🚀
Netick
HomeDownloadDiscord
  • Understanding Client-Server Model
  • Core Concepts
  • Network State
  • Change Callback
  • Remote Procedure Calls (RPCs)
  • RPCs vs Properties
  • Listening to Network Events
  • Understanding Client-Side Prediction
    • Writing Client-Side Prediction code
  • Interpolation
  • Lag Compensation
  • Network Object Instantiation and Destruction
    • Network Prefab Pool
  • Parenting
  • Managing Netick
  • Script Execution Order
Powered by GitBook
On this page
  • For Properties
  • For Arrays

Was this helpful?

Change Callback

For Properties

You can have a method get called whenever a networked property changes, which is very useful. To do that, add the attribute [OnChanged] to the method and give it the name of the property. The method must have one parameter of the same type of the property which would contain its previous value.

Example:

[Networked]
public int Health { get; set; }

[OnChanged(nameof(Health ))]
private void OnHealthChanged(int previous)
{
        // Something that happens when the Health property changes
}

For Arrays

If you have an array and want a callback for when an element changes, you can do so as follows:

Example:

[Networked(size: 10)]
public NetworkArray<int> Items { get; set; }

[OnChanged(nameof(Items))]
private void ArrayChanged(int index)
{
      // Something that happens when an element of the array changes
}

The difference here to a variable property is that the callback method must have an index parameter that points to the changed element.

PreviousNetwork StateNextRemote Procedure Calls (RPCs)

Last updated 1 year ago

Was this helpful?