Search Unity

Question Resources Won't Instantiate Until a Prefab is Modified

Discussion in 'Prefabs' started by KnightsFan, Apr 3, 2021.

  1. KnightsFan

    KnightsFan

    Joined:
    Jan 2, 2014
    Posts:
    29
    I'm having a really strange problem. I am instantiating resources using Resources.Load() when a scene starts. Every time I open my project, if I play a scene, it throws this error:
    ArgumentException: The Object you want to instantiate is null.

    That error will appear every time I run any scene, until I do the following:
    If I then modify any prefab in the project, then the error goes away, and does not appear for the remainder of the session. When I close Unity and re-open the project, the error is back until I open a prefab and modify it. Typically, I open a random prefab, turn a component off, save the prefab, turn it back on, save the prefab, and then everything will work until I close Unity again. Keep in mind the prefab file doesn't actually need to change--git doesn't detect any changes--it's like I just need to jump start some sort of database refresh.

    This has been going on for some months now and is present for all members of the project. I believe it started when I upgraded to the new Unity XR plugin management system. It showed me a message at that time saying there was a GUID conflict, but I didn't see any adverse effects at the time. Then it started throwing this error. We're currently on Unity 2020.2.2f1, but this project was started 8 years ago so has been through many version upgrades.

    tl;dr: Resources.Load() doesn't work until I modify and save a prefab; this repeats every time I close and open Unity.

    It seems like the resource database is messed up somehow, or is not refreshing. I've tried deleting my Library folder. I also tried running AssetdataBase.Refresh() from a menu option. But neither helped, long term or short term. Does anyone have any ideas on how to solve this? Thanks!
     
  2. pietrodenicola

    pietrodenicola

    Unity Technologies

    Joined:
    Dec 8, 2020
    Posts:
    43
    KnightsFan likes this.
  3. KnightsFan

    KnightsFan

    Joined:
    Jan 2, 2014
    Posts:
    29
    Thanks! I will try to reproduce it in a smaller project and submit if so.

    I did however remove and then reinstall all my packages, and the libraries for PUN and TextMeshPro. Since then I haven't had it happen again. So it's possible that it's solved. I'll update this topic after I've done more work in the project, whether the bug returns or not.
     
    pietrodenicola likes this.
  4. KnightsFan

    KnightsFan

    Joined:
    Jan 2, 2014
    Posts:
    29
    Unfortunately, members of my team are still experiencing it, so reinstalling the packages and libraries did not solve it. I'm still unable to reproduce in a smaller project either. Will keep trying.