3 ms·
In case of Unity specifically, yes, re-using entire GameObjects whenever possible goes a long way. In game code, you can use structs instead of managed objects
by throwuxiytayq 5y ago
In case of Unity specifically, yes, re-using entire GameObjects whenever possible goes a long way. In game code, you can use structs instead of managed objects to avoid touching the GC. Unity provides NativeCollections, which are some standard collection data structures that can be used to store structs outside managed memory (which lets you avoid the GC).
In real life it's next to impossible to avoid GC completely (especially if you rely on assets/libraries/even built-in engine features), but that isn't the goal - it's enough that you avoid allocating managed objects during gameplay simulation. GC can do its thing during level loading, cutscenes, in UI, etc.