Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Changing any variable in a prefab removes it as a script reference.

Discussion in 'Editor & General Support' started by The702Guy1, Jun 19, 2023.

  1. The702Guy1

    The702Guy1

    Joined:
    Apr 24, 2022
    Posts:
    48
    I just recently upgraded a project to 2022.3.2f1 LTS from 2022.1.9f1 a couple days ago and since then I have been getting this very annoying bug. If I edit a prefab in the inspector and make a value change to it, such as changing a variable in a related script in the inspector for the prefab, it then removes that prefabs reference in what ever script it was associated with.

    For example I have a script in my scene that handles boss spawning and has references to the prefabs of each of the bosses assigned to the script in the inspector. If I go into one of the boss prefabs and change a value such as speed, or how many projectiles to shoot, etc. the boss handler script no longer references it and I have to reassign the reference every single time. This has never happened in any other version of Unity for me. Any ideas?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    That's a downgrade, which can cause a lot of issues because of how different stuff is formatted
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    Nah, just mentioned in the wrong order (to => from). ;)

    Do you use source control? If so, check in all changes. Then make a change in the prefab and check source control what actually DID change.

    It sounds a little like a meta file out of synch issue but this shouldn't occur for prefabs.
    I would also check any editor code that may run, such as what happens in OnValidate or scripts that have [ExecuteInEditMode] respectively [ExecuteAlways]. This can interfere in unexpected ways.

    We'd have to seem more of the scripts though.
     
    DevDunk likes this.
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Woah, I did not have my morning coffee yet.
     
    Kurt-Dekker likes this.
  5. The702Guy1

    The702Guy1

    Joined:
    Apr 24, 2022
    Posts:
    48

    If I change the code in the prefab from a script directly it does not remove it as a reference, its only if I change a value for a prefab inside the inspector. If I change a value for the prefab in the inspector, the game object that was holding it as a reference changes to "Missing" and I have to reassign it as a reference again.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,558
    Fields going blank like that is often simply because you made an asset on disk (such as this prefab or a scriptable object) reference something in a scene. That doesn't work.
     
  7. The702Guy1

    The702Guy1

    Joined:
    Apr 24, 2022
    Posts:
    48

    That's not what I'm doing though, I have an object in my scene referencing a prefab the prefab is not in my scene at all. Its when I change the prefab variables by opening the prefab in the inspector and changing values that the object that is in the scene loses reference to the prefab. I've been working on this project for a few months and the references didn't start breaking like this until upgrading unity. Not sure if there is something I can do to stop this from continuing.
     
  8. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,718
    You should report a bug if you can reproduce it.