When Loading a Resource during the "AfterSceneLoad" initialization type, the Loading process fails

Issue #723 new
Andrei Buta (Fan Studio UK) created an issue
  1. What happened?
  • When Loading a Resource prefab (that has a MonoBehaviour script attached to it) during the "AfterSceneLoad" initialization type, the Loading process fails, only when also having Odin added to the project.
  1. How can we reproduce it?
  • a. Open the attached project and wait for the import process to finish.
    Now, import Odin into the project.
  • b. Close Unity Editor and reopen it again.
  • c. Enter Play mode.
  • d. A Debug Error message will be logged, from the script that tries to load the resource.
  1. If screenshots would help explain or demonstrate your issue, please include these. N/A

  1. What version of Unity are you using?
  • Unity version 2019.4.16f1
  1. What version of Odin are you using? (See "Tools > Odin Inspector > About")
  • Odin version
  1. Do you have Editor Only mode enabled?
  • Yes.
  1. What operating system are you on?
  • Windows 10 x64 Professional.

Comments (11)

  1. Tor Esa Vestergaard

    Hmm, curious. From the description, I doubt Odin is directly at fault, but it might indirectly be triggering some other bug somewhere. Could you also include the reported error message that you are getting and the full stacktrace it contains?

  2. Andrei Buta (Fan Studio UK) reporter

    There is no stacktrace because there is no crash in the repro project, it’s just that the prefab from the Resource folder is not loaded.
    It seems that Odin somehow is interfering with Unity’s “[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]” cycle.

    If you look at the repro project you’ll see that our test prefab just silently fails to load and we get a null reference.
    As soon as we remove Odin from the repro project and we restart the editor, the “[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]” behaves normally and our test prefab is loaded ok.

  3. Tor Esa Vestergaard

    KAJed on Discord has been doing some testing after your earlier discussion, and it seems that switching the project to AssetDatabase v1 might fix the issue. I would say that also confirms that the issue is on Unity’s side - I can’t imagine what we could do to fix the issue on our end. I would suggest that you report it to Unity for them to repro and hopefully one day we will have an AssetDatabase v2 that’s as stable and reliable as v1 is.

    It would be great if you could confirm whether this does in fact fix the issue for you.

  4. Andrei Buta (Fan Studio UK) reporter

    Hi Tor,

    Thank you very much for your feedback. I had a look over and tried to find a work-around using your advice and see how the bug is tied to the AssetDb2 pipeline. The thing is that there is no chance I can go back and use a DEPRECATED asset pipeline.

    I'm both a Unity and Odin client, and the project I sent is clearly showing that Odin is possibly causing low-level problems like the one described (and perhaps with other known third party plugins). It's evident that Odin and Unity are not playing nice together when using this Unity feature (RunTimeInitializeOnLoad) - that's why I am counting on your support.

    I'm not looking for a scapegoat, I'm just a client that paid for both these amazing tools, and I would appreciate that Odin which highlights the issue described will work directly with Unity because it's mostly a quarrel between the two and I do not have Odin's source code to investigate further or provide extra details to Unity.

    With Unity's help, I'm sure you can investigate further, much faster using the repro steps provided and find out what's happening thus benefiting a possible ugly bug that might affect even more customers in the future.

    As a paying customer, I'm asking for your help to allow me to use Odin together with Unity, as at the moment, it's affecting our on-going project, and we cannot continue further.

    Thank you,


  5. Vasily Povalyaev

    Issue disappears if you reimport anything in the project or add a new asset, and reappears again after you restart the editor

  6. Vasily Povalyaev

    Issue is reproducible even without RuntimeInitializeOnLoadMethod

    public class NewBehaviourScript : MonoBehaviour
        void Start()
            var prefab = Resources.Load("TestPrefab");
            if (prefab == null)
                Debug.LogError("Error loading prefab");

  7. Tor Esa Vestergaard

    Unfortunately, however much I would like to help, the fact remains that we cannot do anything about this on our own end, because all Odin is doing is existing, and we cannot really fix that. I have made and sent a bug report to Unity with repro steps and all the info I have. Hopefully they will be able to reproduce the issue and figure out what is wrong.

    I will post any new information here as it arrives, but I wouldn’t expect a speedy resolution given the current covid times and the fact that it’s Christmas at the moment.

    Meanwhile, there’s not much advice I can offer you, save to revert to AssetDatabase v1, which is in every case I know of significantly more stable and functional than v2 is.

  8. Tor Esa Vestergaard

    To give an update here, Unity reports that they have reproduced this issue and that it can be followed here on their public issue tracker, though it might take an hour or two before the issue appears properly and will show up as missing before then.

  9. Log in to comment