Skip to content

NetEntity

Denis Totmin edited this page Jul 12, 2022 · 13 revisions

NetEntity

  • An abstract class that implements basic functionality of network entities such as network objects, players, mobs, bots, npc and others. It is considered part of the Hi level API and is not required to be implemented.

Properties

int NetId - unique entity identifier, assigned automatically by the server (read only)

int OwnerClientId - Identifier of the entity owner (if 0, then the server host)

Client OwnerBaseClient - Reference to the owner (may be null)

string PrefabName - Text Identifier. Usually used to map a network entity to the game object representing it.

Instance Instance - link to the instance where the entity is located

Transform transform - data on position and orientation in space

NetEntityLossOwnerLogic LossOwner - Choice of entity logic at the loss of the owner

byte[] initData - extended data set in the form of an array of bytes, which is passed to clients along with the entity creation data. The data will appear in the object that came in the event connection.Events.OnGalaxyNetEntityInstantiate in the InitData field

GalaxyVars GalaxyVars - manager for network variables.

bool IgnoreNetVisible - Whether to ignore the network visibility mechanism (used only in InstanceOpenWorldOctree)

bool searchRangeVisible - Search range of visible objects (used only in InstanceOpenWorldOctree)

float OctreeThreshold - Range threshold causing coordinates update in the search tree (used only in InstanceOpenWorldOctree)

bool IsStatic - allows you to enter the object in a static state, reducing the cost of the server to maintain it. The object will not transmit a transformation change, its Update will stop, and netVars synchronization will stop. This data will be frozen at the moment of entering a static state, and will be transmitted to other players in order to display the frozen state of the object. Sending and receiving messages will continue to work in static mode.


Constructors

NetEntity(Instance instance, GalaxyVector3 position = null, GalaxyQuaternion rotation = null, NetEntityAutoSync syncType = NetEntityAutoSync.position_and_rotation)

  • Instance instance - a link to the instance where this object will be created. It cannot be empty, because a network entity cannot exist outside of an instance.
  • GalaxyVector3 position - spatial position
  • GalaxyQuaternion rotation - spatial orientation
  • NetEntityAutoSync syncType - type of automatic synchronization

Methods

void Init(byte[] data = null) - object initialization, and the beginning of its synchronization. You can put an array of bytes from ConvertToBytes to restore the previously saved state of the entity.

SendToOwner(byte code, INetworkSerrializeble message, GalaxyDeliveryType deliveryType) - Sends a message only to the owner of the entity

SendToOwner(byte code, byte[] data, GalaxyDeliveryType deliveryType) - Sends a message only to the owner of the entity

SendMessage(byte code, INetworkSerrializeble message, GalaxyDeliveryType deliveryType) - send a message to all instances of the entity

  • byte code - user message code
  • INetworkSerrializeble message - The object that implements the INetworkSerrializeble interface. For example BaseMessage or BitGalaxy
  • GalaxyDeliveryType deliveryType - way of delivering messages

SendMessage(byte code, byte[] message, GalaxyDeliveryType deliveryType) - send a message to all instances of the entity

  • byte code - user message code
  • byte[] message - user message as an array of bytes
  • GalaxyDeliveryType deliveryType - way of delivering messages

void SendMessageExcept(Client client, byte code, byte[] data, GalaxyDeliveryType deliveryType) - Send a message to all instances of the entity other than the one at the specified client

  • Client client - link to the excluded client
  • byte code - user message code
  • byte[] data - user message as an array of bytes
  • GalaxyDeliveryType deliveryType - way of delivering messages

void SendMessageExcept(CClient client, byte code, INetworkSerrializeble message, GalaxyDeliveryType deliveryType) - Send a message to all instances of the entity other than the one at the specified client

  • Client client - link to the excluded client
  • byte code - user message code
  • INetworkSerrializeble message - The object that implements the INetworkSerrializeble interface. For example BaseMessage or BitGalaxy
  • GalaxyDeliveryType deliveryType - way of delivering messages

void Destory() - removes the entity

void ChangeOwner(Client client = null) - Change the owner of the entity to the specified client (if null, the server becomes the owner)

void ChangeOwnerRandom() - Change the owner to a random owner with load balancing in mind.

byte[] ConvertToBytes() - Serializes the full state of the entity into an array of bytes. Can be used for long term persistence of an entity, or to create your own mechanism for transferring the state of an entity.

void SetIgnoreVisible() - Allows you to exclude an entity from the network visibility mechanism. Usually used for objects that should always be visible.


Abstract methods

void Start() - Called on successful initialization

void Update() - each network frame is called. Based on the frame rate of the instance

void InMessage(byte code, byte[] data, Client client) - a new incoming message. As a rule, messages sent directly by clients via an entity link end up here.

  • byte code - custom message code
  • byte[] data - array of bytes sent by the user
  • Client client- Who sent the message

void OnDestroy() - Called when the object is deleted


The page was edited with the current version of the kernel 0.9.8

Clone this wiki locally