Table of Contents

Class TargetController

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Controls targeting logic for a character, including raycasting, target selection, and target events.

public class TargetController : CharacterBehaviour, ITargetController, ICharacterBehaviour
Inheritance
Object
Component
Behaviour
MonoBehaviour
NetworkBehaviour
TargetController
Implements
Inherited Members
NetworkBehaviour.IsSpawned
NetworkBehaviour.ComponentIndex
NetworkBehaviour.NetworkObject
NetworkBehaviour.MAXIMUM_NETWORKBEHAVIOURS
NetworkBehaviour.UNSET_NETWORKBEHAVIOUR_ID
NetworkBehaviour.ToString()
NetworkBehaviour.Reset()
NetworkBehaviour.OnValidate()
NetworkBehaviour.IsBehaviourReconciling
NetworkBehaviour.ClearReplicateCache()
NetworkBehaviour.CreateReconcile()
NetworkBehaviour.Reconcile_Reader<T>(PooledReader, ref T)
NetworkBehaviour.OnStartServerCalled
NetworkBehaviour.OnStartClientCalled
NetworkBehaviour.WritePayload(NetworkConnection, Writer)
NetworkBehaviour.ReadPayload(NetworkConnection, Reader)
NetworkBehaviour.OnStartNetwork()
NetworkBehaviour.OnStopNetwork()
NetworkBehaviour.OnStartServer()
NetworkBehaviour.OnStopServer()
NetworkBehaviour.OnOwnershipServer(NetworkConnection)
NetworkBehaviour.OnSpawnServer(NetworkConnection)
NetworkBehaviour.OnDespawnServer(NetworkConnection)
NetworkBehaviour.OnStartClient()
NetworkBehaviour.OnStopClient()
NetworkBehaviour.OnOwnershipClient(NetworkConnection)
NetworkBehaviour.ClearBuffedRpcs()
NetworkBehaviour.ExcludeOwnerFromUnbufferedObserversRpcs
NetworkBehaviour.IsClientOnly
NetworkBehaviour.IsServerOnly
NetworkBehaviour.IsHost
NetworkBehaviour.IsClient
NetworkBehaviour.IsServer
NetworkBehaviour.IsDeinitializing
NetworkBehaviour.NetworkManager
NetworkBehaviour.ServerManager
NetworkBehaviour.ClientManager
NetworkBehaviour.ObserverManager
NetworkBehaviour.TransportManager
NetworkBehaviour.TimeManager
NetworkBehaviour.SceneManager
NetworkBehaviour.PredictionManager
NetworkBehaviour.RollbackManager
NetworkBehaviour.NetworkObserver
NetworkBehaviour.IsClientInitialized
NetworkBehaviour.IsClientStarted
NetworkBehaviour.IsClientOnlyInitialized
NetworkBehaviour.IsClientOnlyStarted
NetworkBehaviour.IsServerInitialized
NetworkBehaviour.IsServerStarted
NetworkBehaviour.IsServerOnlyInitialized
NetworkBehaviour.IsServerOnlyStarted
NetworkBehaviour.IsHostInitialized
NetworkBehaviour.IsHostStarted
NetworkBehaviour.IsOffline
NetworkBehaviour.IsNetworked
NetworkBehaviour.GetIsNetworked()
NetworkBehaviour.IsManagerReconciling
NetworkBehaviour.Observers
NetworkBehaviour.IsOwner
NetworkBehaviour.IsController
NetworkBehaviour.HasAuthority
NetworkBehaviour.Owner
NetworkBehaviour.OwnerId
NetworkBehaviour.ObjectId
NetworkBehaviour.LocalConnection
NetworkBehaviour.OwnerMatches(NetworkConnection)
NetworkBehaviour.Despawn(GameObject, DespawnType?)
NetworkBehaviour.Despawn(NetworkObject, DespawnType?)
NetworkBehaviour.Despawn(DespawnType?)
NetworkBehaviour.Spawn(GameObject, NetworkConnection, Scene)
NetworkBehaviour.Spawn(NetworkObject, NetworkConnection, Scene)
NetworkBehaviour.RemoveOwnership()
NetworkBehaviour.GiveOwnership(NetworkConnection)
NetworkBehaviour.GetInstance<T>()
NetworkBehaviour.TryRegisterInstance<T>(T)
NetworkBehaviour.UnregisterInstance<T>()
NetworkBehaviour.CanLog(LoggingType)
MonoBehaviour.IsInvoking()
MonoBehaviour.CancelInvoke()
MonoBehaviour.StopCoroutine(Coroutine)
MonoBehaviour.StopAllCoroutines()
MonoBehaviour.destroyCancellationToken
MonoBehaviour.useGUILayout
MonoBehaviour.didStart
MonoBehaviour.didAwake
MonoBehaviour.runInEditMode
Behaviour.enabled
Behaviour.isActiveAndEnabled
Component.GetComponent<T>()
Component.TryGetComponent<T>(out T)
Component.GetComponentInChildren<T>()
Component.GetComponentsInChildren<T>()
Component.GetComponentInParent<T>()
Component.GetComponentsInParent<T>()
Component.GetComponents<T>()
Component.GetComponentIndex()
Component.CompareTag(TagHandle)
Component.transform
Component.transformHandle
Component.gameObject
Component.tag
Object.GetEntityId()
Object.GetInstanceID()
Object.GetHashCode()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.Destroy(Object)
Object.DestroyImmediate(Object)
Object.DontDestroyOnLoad(Object)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindObjectOfType<T>()
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Object.FindObjectsByType<T>()
Object.FindObjectsByType<T>(FindObjectsInactive)
Object.name
Object.hideFlags

Fields

Last

The previous target information.

public TargetInfo Last

Field Value

TargetInfo

LayerMask

The layer mask used for target raycasts.

public LayerMask LayerMask

Field Value

LayerMask

MAX_TARGET_DISTANCE

The maximum distance allowed for targeting.

public const float MAX_TARGET_DISTANCE = 50

Field Value

float

TARGET_UPDATE_RATE

The update rate (in seconds) for target checks.

public const float TARGET_UPDATE_RATE = 0.05

Field Value

float

Properties

ClientSelectedTargetObjectId

SERVER-side view of the owning client's reported target frame: the NetworkObject id the player is looking at, or 0. Advisory — feeds interest management, never combat resolution. See TargetSelectionBroadcast.

public int ClientSelectedTargetObjectId { get; }

Property Value

int

Current

The current target information.

public TargetInfo Current { get; }

Property Value

TargetInfo

HasClientSelectedTarget

True once any client target report has been accepted for this character. Distinguishes "the player reports no target" (authoritative 0) from "this character has no reporting client at all" (an NPC, or an old client), where readers fall back to the cast-scoped Current.

public bool HasClientSelectedTarget { get; }

Property Value

bool

OnTargetChangeTriggers

Triggers invoked when the target changes to a new target.

public List<Trigger> OnTargetChangeTriggers { get; }

Property Value

List<Trigger>

OnTargetClearTriggers

Triggers invoked when the current target is cleared.

public List<Trigger> OnTargetClearTriggers { get; }

Property Value

List<Trigger>

PinnedTarget

The character the owning client has pinned to its target frame, or null.

public Transform PinnedTarget { get; }

Property Value

Transform

Remarks

A pin is a HUD concept: the pinned card stays up while the pointer wanders, so the player can follow one opponent through a fight. It is never a combat target — ability acquisition stays a server-side raycast from the replicated aim — and it lives on the owning client only. On the server this is always null.

Methods

ClearPinnedTarget()

Releases the pinned target, if any.

public void ClearPinnedTarget()

InitializeOnce()

Called after registration for custom initialization logic. Override in derived classes.

public override void InitializeOnce()

OnDestroying()

Called when the object is being destroyed. Clears target events and resets state.

public override void OnDestroying()

ResetState(bool)

Clears client-reported target state on despawn/pool reuse: the next occupant of a pooled object must not inherit the previous player's target frame.

public override void ResetState(bool asServer)

Parameters

asServer bool

ServerSetClientSelectedTarget(int)

Installs a VERIFIED client target report. Server only; callers must have validated the id resolves to a live character in the reporting client's own scene (or pass 0).

public void ServerSetClientSelectedTarget(int targetObjectId)

Parameters

targetObjectId int

TogglePinnedTarget()

Pins the hovered character, or releases the pin when nothing — or the pinned character itself — is under the pointer. Owning client only.

public bool TogglePinnedTarget()

Returns

bool

True when a target is pinned after the call.

TryPinTarget(Transform)

Pins a specific character. Refused for non-characters, unspawned objects and the player's own character. Owning client only.

public bool TryPinTarget(Transform target)

Parameters

target Transform

The transform to pin.

Returns

bool

True when the target is pinned after the call.

UpdateTarget(Vector3, Vector3, float)

Updates and returns the TargetInfo for the current target, tracing from the given origin and direction.

public TargetInfo UpdateTarget(Vector3 origin, Vector3 direction, float maxDistance)

Parameters

origin Vector3

The origin of the ray.

direction Vector3

The direction of the ray.

maxDistance float

The maximum distance for the raycast.

Returns

TargetInfo

The updated TargetInfo.

Remarks

Lag compensated on the server. This is the acquisition step for every targeted ability: AbilityController.ResolveTargetAndSpawn calls it from the replicated aim, and TargetedEntitySelector then resolves the ability onto whatever it decided. A ray is infinitely thin, so it has no width to absorb the gap between where a client renders its peers and where the server holds them — measured at 0.64 m for a 40 ms connection and 2.2 m at 300 ms, against character capsules 0.6 m across. Uncompensated, a laggy player's ray simply misses the character they aimed at. Rewinding the scene for the caster's view puts the ray back where it was pointed.

One physics scene, both peers. The server branch used to be behind #if UNITY_SERVER, which is undefined in the editor the scene server is developed in — so in that configuration the server took the client branch and traced the default physics scene, which for a multi-scene server holds none of the colliders around the character. Asking the character which scene it is in answers correctly on every peer and in every build, and it is what makes the owner and the server trace the same geometry. The aim itself already matches: KCCPlayer quantises the direction through AimDirectionCompression before it enters the replicate, so the owner simulates with the value the server will receive rather than with its raw camera.

Events

OnChangeTarget

Event triggered when the target changes.

public event Action<Transform> OnChangeTarget

Event Type

Action<Transform>

OnClearTarget

Event triggered when the target is cleared (e.g., deselected).

public event Action<Transform> OnClearTarget

Event Type

Action<Transform>

OnPinTarget

Event triggered on the owning client when a target is pinned.

public event Action<Transform> OnPinTarget

Event Type

Action<Transform>

OnUnpinTarget

Event triggered on the owning client when the pinned target is released. The argument is the released transform, or null when it was destroyed out from under the pin.

public event Action<Transform> OnUnpinTarget

Event Type

Action<Transform>

OnUpdateTarget

Event triggered when the target is updated (but not changed).

public event Action<Transform> OnUpdateTarget

Event Type

Action<Transform>