From cc4178580b11634a0b426aeab487e437e5ef284e Mon Sep 17 00:00:00 2001 From: Felipe Marques de Carvalho Date: Fri, 26 Sep 2025 10:26:31 -0300 Subject: [PATCH 1/3] Fix GameplayTags not loading from StreamingAssets on Android (APK/AAB) --- CHANGELOG.md | 6 ++++ Runtime/BuildGameplayTagSource.cs | 50 +++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c20f177..4d3392d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Fixed GameplayTags not loading from StreamingAssets on Android (APK/AAB) + ## [0.1.0-beta.8] - 2025-09-22 ### Fixed diff --git a/Runtime/BuildGameplayTagSource.cs b/Runtime/BuildGameplayTagSource.cs index d4c1c0d..27b852f 100644 --- a/Runtime/BuildGameplayTagSource.cs +++ b/Runtime/BuildGameplayTagSource.cs @@ -1,6 +1,7 @@ using System; using System.IO; using UnityEngine; +using UnityEngine.Networking; namespace BandoWare.GameplayTags { @@ -12,8 +13,11 @@ public void RegisterTags(GameplayTagRegistrationContext context) { try { - using FileStream file = File.OpenRead(Path.Combine(Application.streamingAssetsPath, "GameplayTags")); - using BinaryReader reader = new(file); + string path = Path.Combine(Application.streamingAssetsPath, "GameplayTags"); + byte[] data = LoadData(path); + + using MemoryStream memoryStream = new(data); + using BinaryReader reader = new(memoryStream); while (reader.BaseStream.Position != reader.BaseStream.Length) { @@ -26,5 +30,47 @@ public void RegisterTags(GameplayTagRegistrationContext context) Debug.LogError($"Failed to load gameplay tags from StreamingAssets: {e.Message}"); } } + + private byte[] LoadData(string dataPath) + { + return Application.platform switch + { + RuntimePlatform.Android => LoadDataFromAndroidPackage(dataPath), + _ => LoadDataFromFile(dataPath), + }; + } + + private byte[] LoadDataFromAndroidPackage(string dataPath) + { + using UnityWebRequest request = UnityWebRequest.Get(dataPath); + UnityWebRequestAsyncOperation operation = request.SendWebRequest(); + while (!operation.isDone) { } + +#if UNITY_2020_2_OR_NEWER + if (request.result != UnityWebRequest.Result.Success) +#else + if (request.isNetworkError || request.isHttpError) +#endif + { + if (request.responseCode == 404) + Debug.LogError($"GameplayTags file not found at path: {dataPath}"); + else + Debug.LogError($"Failed to load gameplay tags from StreamingAssets: {request.error}"); + + return Array.Empty(); + } + + return request.downloadHandler.data; + } + + private byte[] LoadDataFromFile(string path) + { + if (!File.Exists(path)) + { + Debug.LogError($"GameplayTags file not found at path: {path}"); + return Array.Empty(); + } + return File.ReadAllBytes(path); + } } } \ No newline at end of file From 72801c0231812f477d97365353a71caa63bfe1ed Mon Sep 17 00:00:00 2001 From: Felipe Marques de Carvalho Date: Mon, 29 Sep 2025 12:13:44 -0300 Subject: [PATCH 2/3] Fix GameplayTags not loading from StreamingAssets on WebGL --- CHANGELOG.md | 1 + Runtime/BuildGameplayTagSource.cs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d3392d..2a3cc74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed GameplayTags not loading from StreamingAssets on Android (APK/AAB) +- Fixed GameplayTags not loading from StreamingAssets on WebGL ## [0.1.0-beta.8] - 2025-09-22 diff --git a/Runtime/BuildGameplayTagSource.cs b/Runtime/BuildGameplayTagSource.cs index 27b852f..68cda87 100644 --- a/Runtime/BuildGameplayTagSource.cs +++ b/Runtime/BuildGameplayTagSource.cs @@ -35,12 +35,13 @@ private byte[] LoadData(string dataPath) { return Application.platform switch { - RuntimePlatform.Android => LoadDataFromAndroidPackage(dataPath), + RuntimePlatform.WebGLPlayer => LoadDataFromWebRequest(dataPath), + RuntimePlatform.Android => LoadDataFromWebRequest(dataPath), _ => LoadDataFromFile(dataPath), }; } - private byte[] LoadDataFromAndroidPackage(string dataPath) + private byte[] LoadDataFromWebRequest(string dataPath) { using UnityWebRequest request = UnityWebRequest.Get(dataPath); UnityWebRequestAsyncOperation operation = request.SendWebRequest(); From 41c35378d2de58c668669cadbc4fe96e7af5e9c4 Mon Sep 17 00:00:00 2001 From: rurumi Date: Thu, 8 Jan 2026 21:24:28 +0800 Subject: [PATCH 3/3] Fix logic in HasAnyInternal by correcting pointer advancement and loop bounds for sorted list intersection. --- .../GameplayTagContainerExtensionMethods.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Runtime/GameplayTagContainerExtensionMethods.cs b/Runtime/GameplayTagContainerExtensionMethods.cs index 92e3c19..0f27524 100644 --- a/Runtime/GameplayTagContainerExtensionMethods.cs +++ b/Runtime/GameplayTagContainerExtensionMethods.cs @@ -47,24 +47,24 @@ private static bool HasAnyInternal(List tagIndices, List otherTagIndic end = ~end; int j = 1; - int i = start + 1; - while (i < end && j < otherTagIndices.Count) + int i = start; + int otherLimit = otherTagIndices.Count - 1; + + while (i < end && j < otherLimit) { - if (otherTagIndices[j] == tagIndices[i]) + int tagVal = tagIndices[i]; + int otherVal = otherTagIndices[j]; + + if (tagVal == otherVal) return true; - if (tagIndices[i] > otherTagIndices[j]) + if (tagVal < otherVal) { i++; - continue; } - - j++; - while (otherTagIndices[j] < tagIndices[i]) + else { j++; - if (j == end) - return false; } }