Values and Messages

Examples are Lua. The same calls exist as Script Canvas events. Typed Script Canvas nodes generated from a Schema are not built yet, so Script Canvas currently uses the same field handle calls. Calls that can fail return an empty string on success, otherwise the reason.

Reading and writing a value #

Find a field handle once, then read and write through the entity’s request bus.

local f = NetRecordAccessRequestBus.Event.FindField(self.entityId, "Lives")

if NetRecordAccessRequestBus.Event.CanWrite(self.entityId, f) then
    NetRecordAccessRequestBus.Event.SetInt(self.entityId, f, 2)
end

local lives = NetRecordAccessRequestBus.Event.GetInt(self.entityId, f)

A Client write to a field it may not write is refused, and the Any Server’s value returns. Without a game object, use the record id instead: FindRecordField, RecordGetInt and RecordSetInt on NetcodeRequestBus.

Reacting to change #

NetRecordAccessNotificationBus raises OnFieldChanged(field) for a bound object. NetcodeNotificationBus raises session and record events such as OnConnected, OnDisconnected, OnRecordCreated and OnRecordRemoved. Record, input, desync, state applied and message events are raised only after the matching Enable...Notifications call, because listening has a cost.

Messages #

A message is declared in the Schema, under rpcs, with a caller rule (owner, anyServer or anyone), an optional subject record and typed parameters.

{ "name": "WaveRequest", "caller": "owner", "mode": 0, "subject": "Pawn",
  "params": [ { "name": "Pawn", "type": "recordId" } ] }
net.EnableRpcNotifications()                         -- once, to be told of messages
local rpc = net.FindRpc("WaveRequest")
local fp  = net.FindRpcField(rpc, "Pawn")

if net.RpcBegin(rpc) then
    net.RpcSetRecordId(fp, self.record)
    local why = net.RpcSendToAnyServer()             -- or ToConnection, ToAll, ToAllExcept, ToObservers
end

-- receive in a NetcodeNotificationBus handler:  OnRpc(rpc, sender)
-- read parameters with net.RpcGetRecordId(field) and the matching getters

Connection numbers are slot numbers from 0, with -1 for none and -2 for the Any Server. The mode value picks a delivery mode defined by the Transport, and mode 0 is the portable default, so a game that only uses mode 0 can change Transport.

Inputs, hashes and snapshots #

For prediction and correction the gem provides ordered inputs (up to 1,024 bytes each, delivered to the Any Server in order and once, resent within a window), state hashes with OnDesync, snapshots and hydration for smoothed values. These are mechanisms, not a finished prediction system. The Arena sample shows them in use. See Samples.

Rate This Article!