Class Pet
Represents a pet NPC, including owner, abilities, orders, and network payload logic.
public class Pet : NPC, ICharacter, ISpawnable, ILootableCorpse, IInteractable, ISceneObject
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourNetworkBehaviourPet
- Implements
- Inherited Members
-
NetworkBehaviour.IsSpawnedNetworkBehaviour.ComponentIndexNetworkBehaviour.NetworkObjectNetworkBehaviour.MAXIMUM_NETWORKBEHAVIOURSNetworkBehaviour.UNSET_NETWORKBEHAVIOUR_IDNetworkBehaviour.ToString()NetworkBehaviour.Reset()NetworkBehaviour.OnValidate()NetworkBehaviour.IsBehaviourReconcilingNetworkBehaviour.ClearReplicateCache()NetworkBehaviour.CreateReconcile()NetworkBehaviour.Reconcile_Reader<T>(PooledReader, ref T)NetworkBehaviour.OnStartServerCalledNetworkBehaviour.OnStartClientCalledNetworkBehaviour.OnStartNetwork()NetworkBehaviour.OnStopNetwork()NetworkBehaviour.OnStopServer()NetworkBehaviour.OnOwnershipServer(NetworkConnection)NetworkBehaviour.OnSpawnServer(NetworkConnection)NetworkBehaviour.OnDespawnServer(NetworkConnection)NetworkBehaviour.OnStartClient()NetworkBehaviour.OnStopClient()NetworkBehaviour.OnOwnershipClient(NetworkConnection)NetworkBehaviour.ClearBuffedRpcs()NetworkBehaviour.ExcludeOwnerFromUnbufferedObserversRpcsNetworkBehaviour.IsClientOnlyNetworkBehaviour.IsServerOnlyNetworkBehaviour.IsHostNetworkBehaviour.IsClientNetworkBehaviour.IsServerNetworkBehaviour.IsDeinitializingNetworkBehaviour.NetworkManagerNetworkBehaviour.ServerManagerNetworkBehaviour.ClientManagerNetworkBehaviour.ObserverManagerNetworkBehaviour.TransportManagerNetworkBehaviour.TimeManagerNetworkBehaviour.SceneManagerNetworkBehaviour.PredictionManagerNetworkBehaviour.RollbackManagerNetworkBehaviour.NetworkObserverNetworkBehaviour.IsClientInitializedNetworkBehaviour.IsClientStartedNetworkBehaviour.IsClientOnlyInitializedNetworkBehaviour.IsClientOnlyStartedNetworkBehaviour.IsServerInitializedNetworkBehaviour.IsServerStartedNetworkBehaviour.IsServerOnlyInitializedNetworkBehaviour.IsServerOnlyStartedNetworkBehaviour.IsHostInitializedNetworkBehaviour.IsHostStartedNetworkBehaviour.IsOfflineNetworkBehaviour.IsNetworkedNetworkBehaviour.GetIsNetworked()NetworkBehaviour.IsManagerReconcilingNetworkBehaviour.ObserversNetworkBehaviour.IsOwnerNetworkBehaviour.IsControllerNetworkBehaviour.HasAuthorityNetworkBehaviour.OwnerNetworkBehaviour.OwnerIdNetworkBehaviour.ObjectIdNetworkBehaviour.LocalConnectionNetworkBehaviour.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.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.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.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.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.nameObject.hideFlags
- Extension Methods
Fields
AttackPriority
The packed order the attack command tries its target choices in; see PetAttackPriority. Held on the pet as well as the owner's controller so the server reads it from the creature it is commanding.
public int AttackPriority
Field Value
OnReadID
Event triggered when a pet's owner ID is read from the network payload.
public static Action<long, Pet> OnReadID
Field Value
PetAbilityTemplate
The template defining this pet's abilities and behavior.
public PetAbilityTemplate PetAbilityTemplate
Field Value
Properties
MovementOrder
Whether the pet is heeling or holding position.
public PetMovementOrder MovementOrder { get; set; }
Property Value
Remarks
Owner-scoped for the same reason as Stance; see WritePayload(NetworkConnection, Writer).
PersistedAttributes
Attribute values restored from the database, applied at spawn.
public List<PetPersistedAttribute> PersistedAttributes { get; set; }
Property Value
Remarks
Staged rather than applied directly for the same reason PetAbilityIDs is:
the pet system fills this in before ServerManager.Spawn, and the values can only
be written once OnStartServer() has built the attribute controller and
rolled the prefab's own bonuses over it. See FishMMO.Shared.Pet.ApplyPersistedState().
PersistedBuffs
Buffs restored from the database, applied at spawn.
public List<PetPersistedBuff> PersistedBuffs { get; set; }
Property Value
PetAbilityIDs
The list of ability template IDs that this pet has learned. The name avoids shadowing Abilities (List<AbilityTemplate>).
public List<int> PetAbilityIDs { get; set; }
Property Value
PetOwner
The character that owns this pet.
public ICharacter PetOwner { get; set; }
Property Value
Remarks
Setting it also declares the pair to AggressionDispatcher, so that from then on threat against either is threat against both: hit the owner and the pet answers, hit the pet and the owner answers. Clearing it (dismissal, death, pool reset) removes the link again. Any owner qualifies; an NPC handed a pet gets the same rule.
Stance
How willing this pet is to start a fight on its own.
public PetStance Stance { get; set; }
Property Value
Remarks
Server-authoritative, and owner-scoped: the owning client learns it from
PetAddBroadcast and from PetStanceBroadcast, never from the spawn
payload, and never sets it locally — so a modified client cannot put its pet into a
stance the server disagrees with, and an onlooker is not told what orders somebody
else's pet is under.
Methods
CaptureKnownAbilities()
Records the abilities the pet currently knows into PetAbilityIDs so they survive a despawn / re-summon cycle.
public void CaptureKnownAbilities()
Remarks
Called by the pet system before persisting. Without it, abilities granted at summon time from the PetAbilityTemplate were never written to the database and a re-logged pet came back empty.
Despawn()
Returns the pet to the pool immediately, skipping the corpse decay timer.
public override void Despawn()
Remarks
A pet's lifetime is tied to its owner rather than to an ObjectSpawner, so it skips the corpse timer and despawns through the network manager directly. ReturnToPool() routes through the spawner, which a pet does not have, so the previous implementation called it and silently did nothing.
A genuine override, not the new it used to be. Method hiding only applies
when the caller's static type is Pet; anything holding the pet as an
NPC or an ISpawnable — which is how the spawner and several
death paths see it — would silently get the NPC corpse behaviour instead, leaving the
pet parked in the world as an immortal, AI-disabled corpse that nothing ever collects.
LearnAbilities(List<int>)
Records the ability template IDs this pet should know.
public void LearnAbilities(List<int> abilities)
Parameters
Remarks
Only records them. Call LearnPersistedAbilities() to actually teach them to the ability controller — which is the step that was missing entirely: pet ability IDs were loaded from the database, held on this list, and saved back out without ever reaching an IAbilityController, so every pet spawned with an empty spellbook and could never attack.
LearnPersistedAbilities()
Teaches every template ID in PetAbilityIDs to the pet's ability controller, skipping any it already knows.
public void LearnPersistedAbilities()
Remarks
Server-only in effect: the controller is populated authoritatively and replicated, the same way NPC teaches its inspector-configured list.
OnAwake()
Called when the pet is awakened. Initializes the abilities list.
public override void OnAwake()
OnStartServer()
Server spawn. Runs after OnStartServer() has taught the prefab's own ability list, and adds anything restored from the database on top.
public override void OnStartServer()
Remarks
This is the last point at which restored state can be written and still reach clients
in the spawn payload. FishNet invokes the start callbacks during
SpawnWithoutChecks and only writes each observer's payload afterwards, in the
observer rebuild — so anything applied here is serialised, and anything applied after
ServerManager.Spawn returns is not.
ReadPayload(NetworkConnection, Reader)
Reads the pet's payload from the network: the owner's character ID and nothing else.
public override void ReadPayload(NetworkConnection connection, Reader reader)
Parameters
connectionNetworkConnectionThe network connection.
readerReaderThe network reader.
Remarks
See WritePayload(NetworkConnection, Writer) for why the orders are not here.
ResetState(bool)
Resets the pet's state, clearing owner, orders, and abilities.
public override void ResetState(bool asServer)
Parameters
asServerboolWhether the reset is performed on the server.
WritePayload(NetworkConnection, Writer)
Writes the pet's payload to the network: the owner's character ID.
public override void WritePayload(NetworkConnection connection, Writer writer)
Parameters
connectionNetworkConnectionThe network connection.
writerWriterThe network writer.
Remarks
The owner ID genuinely belongs to every observer — Client.OnPetReadId resolves it
to a name for the possessive line on the pet's nameplate, which everyone sees.
Stance and MovementOrder are NOT written. They are the
owner's private command state and no non-owner path reads them; the owner receives both
— plus AttackPriority, which was never in the payload at all — in
PetAddBroadcast, which the pet system sends immediately after
ServerManager.Spawn on both spawn paths (a fresh summon and the database load a
relog goes through). That broadcast is also what assigns PetController.Pet, so it
is already load-bearing: without it the pet UI never binds, and with it the two bytes
here were only ever overwritten by the same values a moment later.