Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

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

Discussion in 'Experimental Scripting Previews' started by ChrisDirkis, Jul 13, 2018.

  1. ChrisDirkis

    ChrisDirkis

    Joined:
    Jun 1, 2017
    Posts:
    38
    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 https://docs.unity3d.com/ScriptReference/AssetPostprocessor.html ).

    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.
     
  2. ChrisDirkis

    ChrisDirkis

    Joined:
    Jun 1, 2017
    Posts:
    38
    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.
     
    neilsarkar likes this.