EDIT the question
I create a small project and in that I have imported a third party project.
Everything works perfectly in the Unity editor.
The game is very simple and it is only necessary to touch a button for two balls to start moving.
The problem arose when I created a build for (Build And Run), as the game starts perfectly but when I touch the mouse button to start moving the balls, it doesn’t work.
The button does not work and checking the Google console shows me the following error every time I touch the button to start.
project.framework.js.gz:3 InvalidOperationException: Garbage collection mode setting is not supported on this platform
I’ve never seen this, I’ve searched this community for other similar issues, but can’t find any
The button works perfectly in the Unity editor and on mobile devices, only this button doesn’t work in WebGL, when we run the game in the browser.
Thanks to @CodeSmile answer, I’ve read more documentation about Garbage Collector.
In the project there is a file that I show below and it is the cause of the button not working correctly in WebGL.
Delete said file and its references in other files, and everything works fine on PC, Devices, and WebGL.
As I said, I have read the documentation about Unity’s Garbage Collector but I still don’t understand what it does.
The game uses Garbage Collector in various parts, see:
public void ResumeGame()
{
GarbageCollectionManager.CollectGarbage();
PausePanel.SetActive(false);
StartCoroutine(WaitToResume());
}
public void GameOver()
{
GarbageCollectionManager.CollectGarbage();
TheGlobals.playingMode = false;
}
Can you give me an idea why this happens?
Where is there information on this?
Could removing this Garbage Collector reference hurt my project in the long run?
Thank you
using System;
using UnityEngine;
using UnityEngine.Scripting;
public static class GarbageCollectionManager
{
public static void DisableGC()
{
#if !UNITY_EDITOR
GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
#endif
}
public static void CollectGarbage()
{
#if !UNITY_EDITOR
GarbageCollector.GCMode = GarbageCollector.Mode.Enabled;
GC.Collect();
GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
#endif
}
}
The framework may not be compatible with Unity WebGL. Consult the docs or the devs. However, that framework is deprecated in case you didn’t know: GameCircle Announcement | GameCircle
Thanks for your reply.
I must say that GameCircle is just the name of the Game.
Regarding GarbageCollector .GCMode, I have gone through the documentation several times, but. I don’t understand how this can affect my game, so I don’t know what I should do.
In none of the projects that I saw before I found this problem.
The project actually has the following file, which is referenced somewhere in the application like so:
GarbageCollectionManager.CollectGarbage();
The file that creates this is the one I added to my question:
Do you know why this happens and what function Garbage Collection has?
I’ve read the Unity documentation over and over again, but I don’t understand what exactly does this.
I must say that if I remove this file and all its references in the application, everything works perfectly
I don’t understand how this function works
Thanks for spend your time on me
using System;
using UnityEngine;
using UnityEngine.Scripting;
public static class GarbageCollectionManager
{
public static void DisableGC()
{
#if !UNITY_EDITOR
GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
#endif
}
public static void CollectGarbage()
{
#if !UNITY_EDITOR
GarbageCollector.GCMode = GarbageCollector.Mode.Enabled;
GC.Collect();
GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
#endif
}
}
Generally, disabling GC is only meaningful for a short period of time, ie within a frame. Or as this class implies, to manually run the garbage collector at specific points in time.
I’d say you don’t need that and shouldn’t use it, since it seems to be incompatible with WebGL.
Some background on garbage collection: Garbage collection (computer science) - Wikipedia
Essentially it’s your mom cleaning up your room (ie memory) after you’ve been playing (ie allocating memory by instantiating objects). It’s an automated process but will not necessarily happen at the most convenient time or frequency.