[InitializeOnLoad] and [DidReloadScripts] not running when .NET4.6 errors prevent compile

As per the title. I’ve got a .unitypackage (internally used) with a bunch of .NET4.6 code in it, as well as a copy of the PlayerSettings of the project it was exported from. This kinda works, throws errors on import but runs fine when the user restarts the editor.

I wanted to automate this, so I figured that I could make a .NET3.5 DLL which would build fine even if the runtime was still 3.5, and do that restart. However, neither of the attributes mentioned in the title appear to be running. I was under the impression that these would work, similarly to AssetPostprocessors still working (see Unity - Scripting API: AssetPostprocessor ).

I’ve tried a few tricks, but the only way this works is if the user manually restarts the editor. If anyone has any guidance on this, it’d be greatly appreciated.

Potentially a bit of a misunderstanding on my part, and probably not related to 4.6 (other than that producing compile errors).

As far as I can tell:
[InitializeOnLoad] only runs on Editor open (when compile errors are there, anyway).
[DidReloadScripts] only runs if there are no compile errors.

Unfortunately, this doesn’t solve my problem, but it’s a start.

1 Like