Skip to content

Conversation

@rurumi0318
Copy link

@rurumi0318 rurumi0318 commented Nov 12, 2025

Fix #16

Add GameplayTagJsonConverter and GameplayTagContainerJsonConverter.
They use the same format as Unreal's convertion of FGameplayTag and FGameplayTagContainer

Formats

GameplayTag

{
    "tagName": "ParentTagA.Middle.LeafA"
}

GameplayTagContainer

{
    "gameplayTags": [
        {
            "tagName": "ParentTagA.Middle.LeafA"
        },
        {
            "tagName": "ParentTagB.Middle.LeafC"
        }
    ]
}

MyClass

[System.Serializable]
public class MyClass
{
    public GameplayTag tag;
    public GameplayTagContainer tagContainer;
}

MyClass to Json

{
    "tag":
    {
        "tagName": "ParentTagA.Middle.LeafB"
    },
    "tagContainer":
    {
        "gameplayTags": [
            {
                "tagName": "ParentTagA.Middle.LeafA"
            },
            {
                "tagName": "ParentTagB.Middle.LeafC"
            }
        ]
    }
}

Example usage

// serialize
MyClass myInstance = CreateInstance();
string JsonString = GameplayTagJsonSettings.Serialize(myInstance);

// deserialize
MyClass deserializedInstance = GameplayTagJsonSettings.Deserialize<MyClass>(jsonString);

Or the user can setup the serializer settings by themself

JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings
        {
            Converters = new Newtonsoft.Json.JsonConverter[]
            {
                new GameplayTagJsonConverter(),
                new GameplayTagContainerJsonConverter()
            }
        };

@rurumi0318
Copy link
Author

GameplayTag is a good tool used in Unreal, and I'm glade that someone can implement it in Unity.

However, the fix makes this pakcage has a dependency to Newtonsoft.Json.
I only added the converters to my local project, but as Newtonsoft.Json is a built-in package of Unity, adding the dependency should be ok...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant