Microsoft.Unity.Analyzers icon indicating copy to clipboard operation
Microsoft.Unity.Analyzers copied to clipboard

Static Fields and Static Event Handlers analyzers for disabling domain reload on entering playmode

Open crocodileindie opened this issue 3 years ago • 4 comments

Problem statement

This feature https://docs.unity3d.com/Manual/ConfigurableEnterPlayMode.html can save users lots of time but comes with hard to identify restrictions especially if you use packages or asset store code https://docs.unity3d.com/Manual/DomainReloading.html

Proposed solution

Static Fields and Static Event Handlers analyzers for disabling domain reload on entering playmode

crocodileindie avatar Jun 19 '22 15:06 crocodileindie

It's an interesting idea. I think we have to keep the concept of "Analyzers", so to prevent but not to intervene: we will not change play mode settings in Unity, but we can simply issue a diagnostic as usual when something looks suspicious.

The only issue here is to properly detect if the project is using configurable play mode. For now analyzers are running in complete isolation, without dependencies towards Unity. They can be run in VS, VSCode (thanks to omnisharp) -even without Unity running- and sometimes directly inside the Unity pipeline.

Perhaps we can use the filesystem, and read project settings. But then we need a minimal parser. I don't know if there is an easy way to quickly detect configurable play mode.

sailro avatar Jun 21 '22 07:06 sailro

cc @jbevain

sailro avatar Jun 21 '22 07:06 sailro

Could an analyser use reflection to check the setting if the UnityEditor.dll is loaded to avoid needing a direct dependency?

SilentSin avatar Jul 09 '22 04:07 SilentSin

I think we need to improve the project generation process to include a define telling us the proper context (is domain reload enabled ?). And we need also to force a re-gen when enabling/disabling this setting in Unity. We are going to discuss that in our next meeting with Unity folks.

sailro avatar Jul 22 '22 13:07 sailro