Struct GhostDistancePartitioningSystem
Automatically adds the GhostDistancePartitionShared shared component to each ghost instance on the server (a structural change), and then updates said component - for each ghost instance - if its Unity.Transforms.LocalTransform.Position changes to a new tile (which is also a structural change, as it needs to update a shared component value). It does this every tick.
Implements
Inherited Members
Namespace: Unity.NetCode
Assembly: Unity.NetCode.dll
Syntax
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation, WorldSystemFilterFlags.Default)]
[UpdateInGroup(typeof(GhostSimulationSystemGroup), OrderFirst = true)]
[BurstCompile]
public struct GhostDistancePartitioningSystem : ISystem, ISystemStartStop, ISystemCompilerGenerated
Remarks
This system only operates if it detects the existence of the GhostDistanceData configuration singleton component within a ServerWorld.
Note that adding the GhostDistancePartitionShared shared component to each ghost instance will almost certainly exacerbate Unity.Entities.ArchetypeChunk entity fragmentation, as we're using the Unity.Entities.ArchetypeChunk system to spatially partition ghost instances. I.e. If there are (for example) just two ghosts of the same archetype within a specific tile, the maximum utilization of their chunk will by 2.
Note that, due to; a) the number of changed positions this system needs to check; b) the frequency of structural changes created by this system; and c) the fragmentation caused by the shared component itself, the impact of enabling importance scaling should be measured, and benchmarked against other possible solutions.
Properties
AutomaticallyAddGhostDistancePartitionSharedComponent
If true (the default), this system will add the GhostDistancePartitionShared shared component to all server ghost instances that meet filtering criteria (Unity.Transforms.LocalTransform etc).
Declaration
public static bool AutomaticallyAddGhostDistancePartitionSharedComponent { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Set to false if you want to use the shared component as a filter, allowing you to only enable importance scaling on a subset of ghost instances. You must therefore add the component yourself.
Methods
CalculateTile(in GhostDistanceData, in float3)
Calculates the tile value for the specified position.
Declaration
public static int3 CalculateTile(in GhostDistanceData ghostDistanceData, in float3 position)
Parameters
| Type | Name | Description |
|---|---|---|
| GhostDistanceData | ghostDistanceData | The ghost distance data |
| float3 | position | The positon |
Returns
| Type | Description |
|---|---|
| int3 | The tile value for the specified position |
OnCreate(ref SystemState)
Called when this system is created.
Declaration
[BurstCompile]
public void OnCreate(ref SystemState state)
Parameters
| Type | Name | Description |
|---|---|---|
| SystemState | state | The Unity.Entities.SystemState backing this system instance |
Remarks
Implement an OnCreate function to set up system resources when it is created.
OnCreate is invoked before the the first time Unity.Entities.ISystemStartStop.OnStartRunning(ref Unity.Entities.SystemState)
and Unity.Entities.ISystem.OnUpdate(ref Unity.Entities.SystemState) are invoked.
OnCreateForCompiler(ref SystemState)
Generated by compilation pipeline and used internally.
Declaration
public void OnCreateForCompiler(ref SystemState state)
Parameters
| Type | Name | Description |
|---|---|---|
| SystemState | state | The Unity.Entities.SystemState backing this system instance |
OnStartRunning(ref SystemState)
Called before the first call to OnUpdate and when a system resumes updating after being stopped or disabled.
Declaration
[BurstCompile]
public void OnStartRunning(ref SystemState state)
Parameters
| Type | Name | Description |
|---|---|---|
| SystemState | state | The Unity.Entities.SystemState backing this system instance |
Remarks
If the Unity.Entities.EntityQuery objects defined for a system do not match any existing entities then the system skips updates until a successful match is found. Likewise, if you set Unity.Entities.SystemState.Enabled to false, then the system stops running. In both cases, Unity.Entities.ISystemStartStop.OnStopRunning(ref Unity.Entities.SystemState) is called when a running system stops updating; OnStartRunning is called when it starts updating again.
OnStopRunning(ref SystemState)
Clean up any/all GhostDistancePartitionShared components that we've added. Note: This will not de-frag fragmented chunks automatically.
Declaration
[BurstCompile]
public void OnStopRunning(ref SystemState state)
Parameters
| Type | Name | Description |
|---|---|---|
| SystemState | state | The Unity.Entities.SystemState backing this system instance |
Remarks
If the Unity.Entities.EntityQuery objects defined for a system do not match any existing entities then the system skips updating until a successful match is found. Likewise, if you set Unity.Entities.SystemState.Enabled to false, then the system stops running. In both cases, OnStopRunning is called when a running system stops updating; Unity.Entities.ISystemStartStop.OnStartRunning(ref Unity.Entities.SystemState) is called when it starts updating again.
OnUpdate(ref SystemState)
Implement OnUpdate to perform the major work of this system.
Declaration
[BurstCompile]
public void OnUpdate(ref SystemState state)
Parameters
| Type | Name | Description |
|---|---|---|
| SystemState | state | The Unity.Entities.SystemState backing this system instance |
Remarks
By default, the system invokes `OnUpdate` once every frame on the main thread. To skip OnUpdate if all of the system's [EntityQueries] are empty, use the [RequireMatchingQueriesForUpdateAttribute]. To limit when OnUpdate is invoked, you can specify components that must exist, or queries that match specific Entities. To do this, call Unity.Entities.SystemState.RequireForUpdate<T>() or Unity.Entities.SystemState.RequireForUpdate(Unity.Entities.EntityQuery) in the system's OnCreate method. For more information, see Unity.Entities.SystemState.ShouldRunSystem().
You can instantiate and schedule an Unity.Entities.IJobChunk instance; you can use the [C# Job System] or you can perform work on the main thread. If you call Unity.Entities.EntityManager methods that perform structural changes on the main thread, be sure to arrange the system order to minimize the performance impact of the resulting [sync points].
[sync points]: xref:concepts-structural-changes
[C# Job System]: https://docs.unity3d.com/Manual/JobSystem.html
[EntityQueries]: xref:Unity.Entities.EntityQuery
[RequireMatchingQueriesForUpdateAttribute]: xref:Unity.Entities.RequireMatchingQueriesForUpdateAttribute