Show / Hide Table of Contents

# Class ServerEntityManager

Server entity manager

##### Inheritance

object
EntityManager
ServerEntityManager

##### Inherited Members

EntityManager.MaxSyncedEntityCount
EntityManager.MaxEntityCount
EntityManager.ServerPlayerId
EntityManager.InvalidEntityId
EntityManager.EntitiesCount
EntityManager.Tick
EntityManager.LerpFactor
EntityManager.UpdateMode
EntityManager.Mode
EntityManager.IsServer
EntityManager.IsClient
EntityManager.FramesPerSecond
EntityManager.DeltaTime
EntityManager.DeltaTimeF
EntityManager.MaxHistorySize
EntityManager.PlayerId
EntityManager.HeaderByte
EntityManager.InRollBackState
EntityManager.InNormalState
EntityManager.VisualDeltaTime
EntityManager.MaxPlayers
EntityManager.IsRunning
EntityManager.RegisterFieldType<T>(InterpolatorDelegateWithReturn<T>)
EntityManager.RegisterFieldType<T>()
EntityManager.GetEntityById<T>(EntitySharedReference)
EntityManager.TryGetEntityById<T>(EntitySharedReference, out T)
EntityManager.GetEntities<T>()
EntityManager.GetControllers<T>()
EntityManager.GetSingleton<T>()
EntityManager.HasSingleton<T>()
EntityManager.AddLocalSingleton<T>(T)
EntityManager.GetLocalSingleton<T>()
EntityManager.TryGetLocalSingleton<T>(out T)
EntityManager.TryGetSingleton<T>(out T)
EntityManager.EnableLagCompensation(NetPlayer)
EntityManager.DisableLagCompensation()
EntityManager.Update()

###### Namespace: LiteEntitySystem

###### Assembly: LiteEntitySystem.dll

##### Syntax

    public sealed class ServerEntityManager : EntityManager

### Constructors

#### ServerEntityManager(EntityTypesMap, InputProcessor, byte, byte, ServerSendRate)

Constructor

##### Declaration

    public ServerEntityManager(EntityTypesMap typesMap, InputProcessor inputProcessor, byte packetHeader, byte framesPerSecond, ServerSendRate sendRate)

##### Parameters

Type | Name | Description
--- | --- | ---
EntityTypesMap | typesMap | EntityTypesMap with registered entity types
InputProcessor | inputProcessor | Input processor (you can use default InputProcessor/ or derive from abstract one to make your own input serialization
byte | packetHeader | Header byte that will be used for packets (to distinguish entity system packets)
byte | framesPerSecond | Fixed framerate of game logic
ServerSendRate | sendRate | Send rate of server (depends on fps)

### Fields

#### MaxStoredInputs

##### Declaration

    public const int MaxStoredInputs = 30

##### Field Value

Type | Description
--- | ---
int |

#### SafeEntityUpdate

Add try catch to entity updates

##### Declaration

    public bool SafeEntityUpdate

##### Field Value

Type | Description
--- | ---
bool |

#### SendRate

Rate at which server will make and send packets

##### Declaration

    public readonly ServerSendRate SendRate

##### Field Value

Type | Description
--- | ---
ServerSendRate |

### Properties

#### PlayersCount

Network players count

##### Declaration

    public int PlayersCount { get; }

##### Property Value

Type | Description
--- | ---
int |

### Methods

#### AddAIController<T>(Action<T>)

Add new AI controller entity

##### Declaration

    public T AddAIController<T>(Action<T> initMethod = null) where T : AiControllerLogic

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T> | initMethod | Method that will be called after entity construction

##### Returns

Type | Description
--- | ---
T | Created entity or null in case of limit

##### Type Parameters

Name | Description
--- | ---
T | Entity type

#### AddController<T>(NetPlayer, PawnLogic, Action<T>)

Add new player controller entity and start controlling entityToControl

##### Declaration

    public T AddController<T>(NetPlayer owner, PawnLogic entityToControl, Action<T> initMethod = null) where T : HumanControllerLogic

##### Parameters

Type | Name | Description
--- | --- | ---
NetPlayer | owner | Player that owns this controller
PawnLogic | entityToControl | pawn that will be controlled
Action<T> | initMethod | Method that will be called after entity construction

##### Returns

Type | Description
--- | ---
T | Created entity or null in case of limit

##### Type Parameters

Name | Description
--- | ---
T | Entity type

#### AddController<T>(NetPlayer, Action<T>)

Add new player controller entity

##### Declaration

    public T AddController<T>(NetPlayer owner, Action<T> initMethod = null) where T : HumanControllerLogic

##### Parameters

Type | Name | Description
--- | --- | ---
NetPlayer | owner | Player that owns this controller
Action<T> | initMethod | Method that will be called after entity construction

##### Returns

Type | Description
--- | ---
T | Created entity or null in case of limit

##### Type Parameters

Name | Description
--- | ---
T | Entity type

#### AddEntity<T>(EntityLogic, Action<T>)

Add new entity and set parent entity

##### Declaration

    public T AddEntity<T>(EntityLogic parent, Action<T> initMethod = null) where T : EntityLogic

##### Parameters

Type | Name | Description
--- | --- | ---
EntityLogic | parent | Parent entity
Action<T> | initMethod | Method that will be called after entity construction

##### Returns

Type | Description
--- | ---
T | Created entity or null in case of limit

##### Type Parameters

Name | Description
--- | ---
T | Entity type

#### AddEntity<T>(Action<T>)

Add new entity

##### Declaration

    public T AddEntity<T>(Action<T> initMethod = null) where T : EntityLogic

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T> | initMethod | Method that will be called after entity construction

##### Returns

Type | Description
--- | ---
T | Created entity or null in case of limit

##### Type Parameters

Name | Description
--- | ---
T | Entity type

#### AddPlayer(AbstractNetPeer)

Create and add new player

##### Declaration

    public NetPlayer AddPlayer(AbstractNetPeer peer)

##### Parameters

Type | Name | Description
--- | --- | ---
AbstractNetPeer | peer | AbstractPeer to use

##### Returns

Type | Description
--- | ---
NetPlayer | Newly created player, null if players count is maximum

#### AddSingleton<T>(Action<T>)

Add new entity

##### Declaration

    public T AddSingleton<T>(Action<T> initMethod = null) where T : SingletonEntityLogic

##### Parameters

Type | Name | Description
--- | --- | ---
Action<T> | initMethod | Method that will be called after entity construction

##### Returns

Type | Description
--- | ---
T | Created entity or null in case of limit

##### Type Parameters

Name | Description
--- | ---
T | Entity type

#### Create<TInput>(EntityTypesMap, byte, byte, ServerSendRate)

Simplified constructor

##### Declaration

    public static ServerEntityManager Create<TInput>(EntityTypesMap typesMap, byte packetHeader, byte framesPerSecond, ServerSendRate sendRate) where TInput : unmanaged

##### Parameters

Type | Name | Description
--- | --- | ---
EntityTypesMap | typesMap | EntityTypesMap with registered entity types
byte | packetHeader | Header byte that will be used for packets (to distinguish entity system packets)
byte | framesPerSecond | Fixed framerate of game logic
ServerSendRate | sendRate | Send rate of server (depends on fps)

##### Returns

Type | Description
--- | ---
ServerEntityManager |

##### Type Parameters

Name | Description
--- | ---
TInput | Main input packet type

#### Deserialize(NetPlayer, ReadOnlySpan<byte>)

Read data from NetPlayer

##### Declaration

    public DeserializeResult Deserialize(NetPlayer player, ReadOnlySpan<byte> inData)

##### Parameters

Type | Name | Description
--- | --- | ---
NetPlayer | player | Player that sent input
ReadOnlySpan<byte> | inData | incoming data with header

##### Returns

Type | Description
--- | ---
DeserializeResult |

#### Deserialize(AbstractNetPeer, ReadOnlySpan<byte>)

Read data for player linked to AbstractNetPeer

##### Declaration

    public DeserializeResult Deserialize(AbstractNetPeer peer, ReadOnlySpan<byte> inData)

##### Parameters

Type | Name | Description
--- | --- | ---
AbstractNetPeer | peer | Player that sent input
ReadOnlySpan<byte> | inData | incoming data with header

##### Returns

Type | Description
--- | ---
DeserializeResult |

#### GetPlayer(byte)

Get player by owner id

##### Declaration

    public NetPlayer GetPlayer(byte ownerId)

##### Parameters

Type | Name | Description
--- | --- | ---
byte | ownerId | id of player owner (Entity.OwnerId)

##### Returns

Type | Description
--- | ---
NetPlayer |

#### GetPlayerController(NetPlayer)

Returns controller owned by the player

##### Declaration

    public HumanControllerLogic GetPlayerController(NetPlayer player)

##### Parameters

Type | Name | Description
--- | --- | ---
NetPlayer | player | player to remove

##### Returns

Type | Description
--- | ---
HumanControllerLogic | Instance if found, null if not

#### GetPlayerController(AbstractNetPeer)

Returns controller owned by the player

##### Declaration

    public HumanControllerLogic GetPlayerController(AbstractNetPeer player)

##### Parameters

Type | Name | Description
--- | --- | ---
AbstractNetPeer | player | player

##### Returns

Type | Description
--- | ---
HumanControllerLogic | Instance if found, null if not

#### GetPlayerController(byte)

Returns controller owned by the player

##### Declaration

    public HumanControllerLogic GetPlayerController(byte playerId)

##### Parameters

Type | Name | Description
--- | --- | ---
byte | playerId | player

##### Returns

Type | Description
--- | ---
HumanControllerLogic | Instance if found, null if not

#### OnLogicTick()

##### Declaration

    protected override void OnLogicTick()

##### Overrides

EntityManager.OnLogicTick()

#### RemovePlayer(NetPlayer)

Remove player and it's owned entities

##### Declaration

    public bool RemovePlayer(NetPlayer player)

##### Parameters

Type | Name | Description
--- | --- | ---
NetPlayer | player | player to remove

##### Returns

Type | Description
--- | ---
bool | true if player removed successfully, false if player not found

#### RemovePlayer(AbstractNetPeer)

Remove player using NetPeer.Tag (is you assigned it or used AddPlayer(AbstractNetPeer) with assignToTag)

##### Declaration

    public bool RemovePlayer(AbstractNetPeer player)

##### Parameters

Type | Name | Description
--- | --- | ---
AbstractNetPeer | player | player to remove

##### Returns

Type | Description
--- | ---
bool | true if player removed successfully, false if player not found

#### Reset()

Remove all entities and reset all counters and timers

##### Declaration

    public override void Reset()

##### Overrides

EntityManager.Reset()