{"repo":"alexisstrat/unity-auto-statics-cleanup-generator","free":true,"listed":false,"github":"https://github.com/alexisstrat/unity-auto-statics-cleanup-generator","clone":"git clone https://github.com/alexisstrat/unity-auto-statics-cleanup-generator.git","description":"Source Generator for cleaning up static fields when Entering/Exiting Play Mode in Unity","language":"C#","stars":51,"topics":["unity","unity3d","source-gen","source-generator","sourcegen","sourcegenerator","unity-editor","unity-editor-tool","unityeditor","unityeditortool"],"license":"MIT","category":"game-templates","readme_excerpt":"AutoStaticsCleanup Generator A backport of Unity 6.5+'s built-in AutoStaticsCleanup source generator to Unity 6.0–6.4. Static fields, properties, and events marked with the [AutoStaticsCleanup] attribute are reset on every Editor play-mode transition. Contents - What it does - Installation - Building from source - Setup - 1. Define the trigger attributes and helper classes - 2. Drop the analyzer DLL into Unity - 3. Use it - Diagnostics - Migrating to Unity 6.5+ - How it works What it does For every static member you opt in, on every Editor play-mode transition: - Settable fields and properties are reassigned to their declared initializer (or default if none). Reference-typed targets get an if (X is not null) X = …; guard so the assignment is a no-op for never-touched fields. - Readonly collections ( static readonly List Items = new() { 1, 2 }; ) are emptied via Clear() and their initializer elements re-added, keeping the reference stable. - Static events are unsubscribed handler-by-handler via GetInvocationList() . - Generic types like class Singleton work out of the box: the cleanup method is emitted inside the open generic, and each closed instantiation registers itself when its static constructor first runs. - Visibility doesn't matter — private and internal members work because the cleanup method is emitted into the target type itself (as a partial-class member) and has direct access. The generated code matches what Unity 6.5's built-in generator produces for the same inp","default_branch":null,"files":null,"tree":[],"storefront":"/r/alexisstrat","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/alexisstrat/unity-auto-statics-cleanup-generator/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}