Unity Atoms

Unity Atoms

  • Installation
  • Tutorials
  • Github

›Subpackages

Introduction

  • Installation
  • Philosophy
  • Overview
  • Preferences
  • FAQ

Tutorials

    Basics

    • Creating Atoms
    • Variables
    • Events
    • Listeners
    • Actions
    • Mono Hooks

    Intermediate

    • Variable Pre Change Transformers
    • Variable Instancer
    • Event Instancer
    • Generator
    • Conditions

    Advanced

    • Advanced example
    • Usage with UniRX

Subpackages

  • Base Atoms
  • FSM
  • Input System
  • Mobile
  • Mono Hooks
  • Scene Mgmt
  • Tags
  • UI

Unity Atoms / Tags

A replacement to Unity's tags based on Unity Atoms.

The Tags subpackage of Unity Atoms is a powerful tool that enhances Unity's existing tag functionality by allowing for dynamic and scriptable tag operations.

Using the Tags subpackage

Adding and removing tags from a GameObject

To assign a tag to a GameObject, use the AtomTags component that comes with the AtomTags subpackage. The easiest way is to add the Tags in the Inspector, but it's also possible to add/remove tags at runtime using StringConstants:

Here's an example:

StringConstant myTag;

...

Tag tagComponent = gameObject.AddComponent<AtomTags>();
tagComponent.AddTag(myTag);
tagComponent.RemoveTag(myTag.Value);

Get tags of an GameObjects

To see if a GameObject has a specific tag:

GameObject go;
...
go.HasTag("a");

or any tag within a list:

go.HasAnyTag(new List<string>() { "d", "f", "h", "j", "l" });

Or to get all the tags a gameobject has:

AtomTags.GetTagsForGameObject(go);

Querying GameObjects by Tags

To find all GameObjects with a specific tag, use the FindObjectsWithTag method:

IEnumerable<GameObject> enemies = AtomTags.FindByTag("Enemy");

This will return all GameObjects with the tag "Enemy".

Performance

The Tag packages is fine tuned to reduce heap allocations as much as possible. Some results are discussed here.

← Scene MgmtUI →
  • Using the Tags subpackage
    • Adding and removing tags from a GameObject
    • Get tags of an GameObjects
    • Querying GameObjects by Tags
  • Performance
Unity Atoms
Docs
InstallationTutorialsSubpackages
Community
DiscordGitter
More
BlogGitHubStar
Copyright © 2023 Adam Ramberg