Skip to content
yenmoc edited this page Jul 3, 2023 · 3 revisions

What

Implement a gameobject identifier with a tag based ScriptableObject

Infomation

Tag

A MonoBehaviour that adds tags the ScriptableObject way to a GameObject.

  • Properties
    • Tags: Get the tags associated with this GameObject as StringConstants in a ReadOnlyList. You can create StringConstant to use as tag via menu Create > Pancake > Scriptable > ScriptableConstants > string
  • Methods
    • HasTag(string): Check if the tag provided is associated with this GameObject. return true if the tag exists, otherwise false.
    • RemoveTag(string): Remove a tag from this GameObject.
    • FindByTag(string): Find first GameObject that has the tag provided. Return the first GameObject with the provided tag found. If no GameObjects found, it returns null.
    • FindAllByTag(string): Find all GameObjects that have the tag provided. Return an array of GameObjects with the provided tag. If not found it returns null.
    • FindAllByTagNoAlloc(string, List<GameObject>): Find all GameObjects that have the tag provided. Mutates the output List and adds the GameObjects found to it.
    • GetTagsForGameObject(GameObject): A faster alternative to gameObject.GetComponent<Tag>(). Returns the Tag component. Returns null if the GameObject does not have a Tag component or if the GameObject is disabled.
    • GetTags(GameObject): Retrieves all tags for a given GameObject. A faster alternative to gameObject.GetComponents<Tag>().Tags. Return a ReadOnlyList<T> of tags stored as StringContants. Returns null if the GameObject does not have any tags or if the GameObject is disabled.

TagExtensions

GameObject extensions related to tags

  • Methods

    • GetTags(GameObject): Retrieves all tags for a given GameObject. A faster alternative to gameObject.GetComponent<Tag>().Tags. A ReadOnlyList of tags stored as StringContants. Returns null if the GameObject does not have any tags or if the GameObject is disabled.

    Now you can use method GetTags directly from gameObject

    var results = gameObject.GetTags();
    • HasTag(GameObject, string): Check if the tag provided is associated with this GameObject. Return true if the tag exists, otherwise false.

    • HasAnyTag(GameObject, List<string>): Check if any of the tags provided are associated with this GameObject. Return true if any of the tags exist, otherwise false.

Clone this wiki locally