AbilityObject - jimdroberts/FishMMO GitHub Wiki

Description

Represents a spawned ability object in the world, handling its lifetime, collision, and event triggers. Used in the FishMMO system to manage the behavior, events, and destruction of ability-related objects such as projectiles, effects, or pets.


API Access

Fields

  • public static Action<PetAbilityTemplate, IPlayerCharacter> OnPetSummon

    Event invoked when a pet ability is summoned.

  • internal int ContainerID

    The container ID for grouping spawned ability objects.

  • internal int ID

    The unique ID for this ability object within its container.

  • public Ability Ability

    The ability instance this object represents.

  • public IPlayerCharacter Caster

    The character who cast or owns this ability object.

  • public Rigidbody CachedRigidBody

    Cached reference to the object's Rigidbody, if present.

  • public int HitCount

    Number of hits this object can perform before being destroyed.

  • public float RemainingLifeTime

    Remaining lifetime in seconds before the object is destroyed.

  • public System.Random RNG

    Random number generator for ability effects.

  • public GameObject GameObject { get; private set; }

    Cached reference to the object's GameObject.

  • public Transform Transform { get; private set; }

    Cached reference to the object's Transform.

Methods

  • private void Awake()

    Unity Awake callback. Caches references and sets Rigidbody to kinematic if present.

  • void Update()

    Unity Update callback. Handles ticking, event dispatch, and lifetime management.

  • void OnCollisionEnter(Collision collision)

    Unity OnCollisionEnter callback. Handles collision logic, event dispatch, and destruction. Parameters:

    • Collision collision: The collision data from Unity.
  • internal void DestroyAbilityObjectInternal()

    Destroys this ability object, dispatching OnDestroy events and cleaning up references.

  • public static void Spawn(Ability ability, IPlayerCharacter caster, Transform abilitySpawner, TargetInfo targetInfo, int seed)

    Handles primary spawn functionality for all ability objects. Returns true if successful. Parameters:

    • Ability ability: The ability instance to spawn.
    • IPlayerCharacter caster: The character casting the ability.
    • Transform abilitySpawner: The spawn point for the ability object.
    • TargetInfo targetInfo: Targeting information for the ability.
    • int seed: Random seed for ability effects.
  • public static void SetAbilitySpawnPosition(IPlayerCharacter caster, Ability ability, Transform abilitySpawner, TargetInfo targetInfo, Transform abilityTransform)

    Handles positioning and rotation of spawned ability objects based on spawn target type. Parameters:

    • IPlayerCharacter caster: The character casting the ability.
    • Ability ability: The ability instance.
    • Transform abilitySpawner: The spawn point for the ability object.
    • TargetInfo targetInfo: Targeting information for the ability.
    • Transform abilityTransform: The transform to set position and rotation for.

Basic Usage

Setup

  1. Attach AbilityObject to prefabs that represent spawned ability effects, projectiles, or pets.
  2. Configure the prefab and its fields as needed in the Unity Inspector or via script.
  3. Integrate with the ability system to spawn, update, and destroy ability objects as abilities are used.
  4. Use the provided events and methods to handle collisions, ticking, and destruction logic.

Example

// Example 1: Spawning an AbilityObject

// This example demonstrates how to spawn an AbilityObject using the static Spawn method.

Ability ability = ...; // Constructed ability instance
IPlayerCharacter caster = ...; // The character casting the ability
Transform spawner = ...; // The spawn point
TargetInfo targetInfo = ...; // Targeting information
int seed = ...; // Random seed

AbilityObject.Spawn(ability, caster, spawner, targetInfo, seed);
⚠️ **GitHub.com Fallback** ⚠️