EllanJiang/GameFramework · error · GameFrameworkException
You can not set current variant at this time.
Error message
You can not set current variant at this time.
What it means
SetCurrentVariant throws this when m_RefuseSetFlag is true, meaning the resource module is already initialized and configuration setters are locked. The current variant (e.g. language/quality asset variant) must be chosen before initialization completes.
Solutions
- Set the variant before initialization (Awake / inspector / bootstrap)
- Load variant settings synchronously before the resource module initializes
- Do not switch variants at runtime; restart the module if necessary
Example fix
// before
IEnumerator Start() { yield return LoadUserPrefs(); resourceComponent.SetCurrentVariant(prefs.Variant); } // refused
// after
void Awake() { resourceComponent.SetCurrentVariant(syncedPrefs.Variant); } Defensive patterns
Strategy: validation
Validate before calling
if (!resourceComponent.Initialized) resourceComponent.SetCurrentVariant(variant); else Log.Warning("Too late to set current variant"); Try / catch
try { resourceComponent.SetCurrentVariant(variant); }
catch (GameFrameworkException) { Log.Error("Current variant must be set before resource initialization completes."); } Prevention
- Load variant/user preferences synchronously before init
- Set the variant in the bootstrap phase (Awake)
- Avoid runtime variant switching; restart the module if needed
When it happens
Trigger: Calling SetCurrentVariant after ResourceManager initialization has completed.
Common situations: Choosing a variant based on user settings loaded asynchronously after startup, or switching language variants at runtime.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- You can not set read-only path at this time.
- You must set read-only path before add load resource agent…
- You can not set read-write path at this time.
- You must set read-write path before add load resource agent…
- You can not set resource mode at this time.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/b5b59c7075f9a93b.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Resource/ResourceManager.cs:970
m_ResourceUpdater.ResourceUpdateComplete += OnUpdaterResourceUpdateComplete;
m_ResourceUpdater.ResourceUpdateAllComplete += OnUpdaterResourceUpdateAllComplete;
}
}
else if (m_ResourceMode != resourceMode)
{
throw new GameFrameworkException("You can not change resource mode at this time.");
}
}
/// <summary>
/// 设置当前变体。
/// </summary>
/// <param name="currentVariant">当前变体。</param>
public void SetCurrentVariant(string currentVariant)
{
if (m_RefuseSetFlag)
{
throw new GameFrameworkException("You can not set current variant at this time.");
}
m_CurrentVariant = currentVariant;
}
/// <summary>
/// 设置对象池管理器。
/// </summary>
/// <param name="objectPoolManager">对象池管理器。</param>
public void SetObjectPoolManager(IObjectPoolManager objectPoolManager)
{
if (objectPoolManager == null)
{
throw new GameFrameworkException("Object pool manager is invalid.");
}
m_ResourceLoader.SetObjectPoolManager(objectPoolManager);
}View on GitHub (pinned to d0c010b051)