Game.Rendering.EffectTransformSystem
Assembly: Assembly-CSharp (likely)
Namespace: Game.Rendering
Type: class
Base: GameSystemBase
Summary:
EffectTransformSystem schedules a Burst-compiled parallel job (EffectTransformJob) that updates the runtime transform-related state (position, rotation, scale, intensity, animation blending, etc.) for enabled effect instances. It reads many component and buffer lookups (transforms, owners, culling, interpolated transforms, bone histories, prefab effect definitions, colors, animations, etc.), applies randomization, bone/sub-mesh attachments, relative/local transforms, curve sampling and light/color logic, and writes results back into the enabled-effect list provided by EffectControlSystem. The system coordinates with RenderingSystem (frame index/time), EffectControlSystem (enabled-effects list), and PreCullingSystem (culling flags) and ensures correct job dependency registration with those systems.
Fields
-
private RenderingSystem m_RenderingSystem
Used to read the current frame index and frame time (frame-based animation evaluation). Populated in OnCreate. -
private EffectControlSystem m_EffectControlSystem
Provides the NativeList of enabled effect entries (m_EnabledData) and is informed about the job writer via AddEnabledDataWriter. Used to obtain and update the enabled effects buffer used by the job. -
private PreCullingSystem m_PreCullingSystem
Provides pre-culling data (m_CullingData) so the job can test whether an effect's owner is near the camera. The system is informed about the job as a reader via AddCullingDataReader. -
private TypeHandle __TypeHandle
Holds ComponentLookup and BufferLookup handles for all component/buffer types used by the EffectTransformJob. __TypeHandle.__AssignHandles is used to initialize these lookups for the current SystemState.
Properties
- None (no public properties declared on this system)
Constructors
public EffectTransformSystem()
Default constructor. Marked with [Preserve] attribute to avoid code stripping in builds. No special initialization beyond the base constructor.
Methods
-
protected override void OnCreate()
Initializes references to required systems: RenderingSystem, EffectControlSystem and PreCullingSystem via World.GetOrCreateSystemManaged(). Called once when the system is created. Marked with [Preserve]. -
protected override void OnUpdate()
Main scheduling method. It: - Constructs an EffectTransformJob instance and fills its ComponentLookup/BufferLookup fields using InternalCompilerInterface.GetComponentLookup / GetBufferLookup (via __TypeHandle).
- Obtains the enabled-effect NativeList from EffectControlSystem.GetEnabledData(out dependencies) and culling data from PreCullingSystem.GetCullingData(out dependencies2).
- Sets jobData.m_FrameIndex and m_FrameTime from m_RenderingSystem.
- Schedules the job as a IJobParallelForDefer over jobData.m_EnabledData with a batch size of 16 and combined dependencies (base.Dependency + dependencies + dependencies2).
- Calls m_EffectControlSystem.AddEnabledDataWriter(jobHandle) and m_PreCullingSystem.AddCullingDataReader(jobHandle) to register the job's access patterns.
-
Stores the returned JobHandle into base.Dependency. This method performs the bulk of the system's work by delegating per-effect computations to the Burst job.
-
private void __AssignQueries(ref SystemState state)
Called by OnCreateForCompiler to set up any EntityQuery objects the compiler expects. Here it constructs and immediately disposes of an EntityQueryBuilder (placeholder). Marked AggressiveInlining. -
protected override void OnCreateForCompiler()
Compiler-time initialization helper. Calls __AssignQueries and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to initialize ComponentLookup/BufferLookup handles. -
[Preserve] public EffectTransformSystem()
(See Constructors) Included in listing above; preserved for linker.
Nested / Job-related methods (inside EffectTransformJob) are described below because they are central to the system's behavior:
- Execute(int index): Processes a single EnabledEffectData entry (by index) from m_EnabledData. It:
- Skips entries that are not enabled or whose relevant flags indicate no transform change.
- Resolves the Effect definition (prefab effect or editor container override).
- Resolves temporary owner redirects (Temp -> original).
- Applies random transform offsets/rotation when RandomTransform flag is set.
- Determines whether to perform full update based on owner-culling, near-camera or presence of an Event component.
- Applies light color/scale adjustments if the effect is marked as a light, including color variation/randomization.
- Computes world position/rotation via different owner component types in priority: InterpolatedTransform, Relative (with bone/submesh support), Curve (bezier sampling), Transform, Node.
- If an animation index is set on the effect and intensity is non-zero, evaluates the appropriate EffectAnimation using PseudoRandomSeed to bias the animation phase per-owner.
- Writes updated fields (position, rotation, scale, intensity) into the EnabledEffectData entry.
- Randomize(ref Color, ref Random, float3 min, float3 max): Converts color to HSV, applies per-channel randomness and clamps, then converts back to RGB.
- IsNearCamera(Entity): Uses CullingInfo component and the PreCullingData list to decide whether the owner is near the camera.
- GetEffectTransform(Effect prefabEffect, Entity owner): If effect attaches to a bone index, looks up BoneHistory and computes transform using bone matrix and optional parent sub-mesh transform. Otherwise returns local effect transform.
- GetRelativeTransform(Relative relative, Entity owner): Similar bone/submesh-relative transform computation for Relative component data.
- TestFlags(EffectConditionFlags requiredFlags, EffectConditionFlags forbiddenFlags, TransformFlags transformFlags): Tests if transform flags satisfy required/forbidden flags in a vectorized manner using math.int4/int4 operations.
- Note: EffectTransformJob is Burst-compiled and implements IJobParallelForDefer. It reads many data sources (ComponentLookup/BufferLookup) and writes into the NativeList
Important job-access and synchronization details: - The job obtains the enabled-effect list (m_EnabledData) and writes back per-entry transforms; EffectControlSystem.AddEnabledDataWriter(jobHandle) is called so EffectControlSystem knows there's an ongoing writer. - The job reads pre-culling data from PreCullingSystem and registers as a reader via AddCullingDataReader(jobHandle). - ComponentLookup/BufferLookup handles are retrieved as read-only where appropriate; the job relies on those lookups being valid for the scheduled job's context.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire systems needed by EffectTransformSystem
m_RenderingSystem = base.World.GetOrCreateSystemManaged<RenderingSystem>();
m_EffectControlSystem = base.World.GetOrCreateSystemManaged<EffectControlSystem>();
m_PreCullingSystem = base.World.GetOrCreateSystemManaged<PreCullingSystem>();
}
Additional tips for modders: - If you need to intercept or modify effect transforms, consider hooking into EffectControlSystem's enabled-data or injecting a system that runs before/after EffectTransformSystem and appropriately registers dependencies (readers/writers) to avoid race conditions. - The job is Burst-compiled and heavily uses Unity.Mathematics types (float3, quaternion, math.*) and Native collections; keep managed allocations out of the job. - For deterministic per-instance randomness the job uses Random.CreateFromIndex((uint)(entity.Index ^ effectIndex)) for random transforms and PseudoRandomSeed for animation offsets — be mindful if you want to reproduce or override random behavior. - Bone / submesh attachment logic relies on BoneHistory and SubMesh buffers; when creating effects that attach to skeletons, ensure those buffers are populated and indices match the expected ranges to avoid skipping the bone-based transform path.