Skip to content

Lasanha-Dev/Unity-GameplayTags

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Unity-GameplayTags

My attempt to replicate Unreal's Gameplay Tags system: https://dev.epicgames.com/documentation/en-us/unreal-engine/gameplay-tags?application_version=4.27

Build

Before building your project make sure that you added your tags container as a preloaded asset, otherwise it will get stripped because there's nothing directly referencing it

11

Registering tags

You can register tags in two ways: Adding native tag / Manually adding a new tag

Manually adding a new tag

You can manipulate tags directly on the ScriptableObject the following way:

1 - Click "Add Root Tag"

2 - Edit Tag Name

3 - Add Subtag

4 - Delete Root/Subtag

0

Adding native tag

To add a native tag you must do that via code the following way:

1 - Locate the NativeGameplayTags class or the one that you created

2 - Add a new const string with the tag name (this const string can be used anywhere in your code to retrieve the tag and avoid typos)

4

3 - Use the AddNativeTag method from the container to add a new native tag

5

Native tags notes

1 - Native tags cannot be deleted on modified directly on the ScriptableObject, they're readonly

2 - If you add a native tag that already exists inside the container, it will replace the tag by the native one

3 - If you remove a native tag from code, it will not revert as a manual tag, it will just be removed from the container

4 - Native tags can also have child tags both added from the ScriptableObject and from code

Gameplay Tags Component

Use this component to hold tags related to your GameObjects

1

You can add Startup Tags and also Add/Remove tags during Runtime

Addings Tag To Gameplay Tags Component

On the Startup Tags you can select any tag from the created ones inside the ScriptableObject (Including native tags) and add as many as you want

2

You can also add via code during runtime which will then trigger an event so that you can perform actions whenever a tag is added/removed

6

GameplayTagSelector Attribute

If you want to select a tag from your custom component you can use the GameplayTagSelector Attribute which allows you to choose a tag to your string field and avoid typos

7 8

Extension Methods

There's also an extension methods helper class which helps you retrieve/add/remove tags from Objects

9 10

Future features

[ ] Replace strings by Guids to improve speed and memory usage - I'm still analysing how I'm going to implement this because there's also the possibility of using string interning, which may improve memory usage for the manually added tags inside the ScriptableObject

[ ] Add more tags comparison fuctions inside Gameplay Tags Component

About

Attempt to replicate Unreal's Gameplay Tags system

Resources

License

Stars

Watchers

Forks

Languages