Search Unity

"Disconnecting is no longer implemented"

Discussion in 'Prefabs' started by Baste, Apr 5, 2019.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,332
    There's a neat feature in Unity where you can swap the script on a component, and keep all fields with the same name. I often use it to swap a base class for a child class. I tried to do it on a prefab variant, and that doesn't work. Here's it in action:

    Bug.gif

    It looks like everything's fine, but I'm actually attempting to disconnect the prefab. The error message is pretty anonymous:

    upload_2019-4-5_11-39-7.png

    ... That's not very helpful! I also didn't notice it at first, and the prefab mode behaved as if nothing was wrong.

    I understand what's going on, as I remember that in 2018.2 and earlier, swapping the script caused prefabs to become disconnected. So it's obvious that this shouldn't be supported. But unless I spot the error message, it looks like this feature is supported in prefab mode, until I leave and recognize that no changes were applied.

    The error behavior should probably be the same as if you try to delete an object from the base prefab:
    upload_2019-4-5_11-41-46.png
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Hi,

    Thanks, can you please turn it in to a bug report. That makes it easier for us to track.
     
    NeatWolf likes this.
  3. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Plus one for this.

    I use it a lot when switching between classes/subclasses, it was a neat way to keep the values of the serialised fields, and I miss it already :)

    I can't reproduce it, tho, using the latest stable version hasn't occurred to me yet.
     
  4. tarahugger

    tarahugger

    Joined:
    Jul 18, 2014
    Posts:
    129
    I'm getting this in 2019.3.0a8 at the moment, fixed a broken script and now it won't save/keep the new reference to the script or any of the values set. It also wont let me open the overrides dropdown for the parent prefab:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.PrefabOverridesTreeView.AddTreeViewItemRecursive (UnityEditor.IMGUI.Controls.TreeViewItem parentItem, UnityEngine.GameObject gameObject, System.Collections.Generic.Dictionary`2[TKey,TValue] prefabOverrideMap, UnityEditor.PrefabOverridesTreeView+IdSequence idSequence) (at <f68ca06da1c243afa30519f1c09ba13a>:0)
     
  5. hashim

    hashim

    Joined:
    Feb 13, 2014
    Posts:
    2
    right click on the gameobject in the hierarchy, select "Open Prefab Asset". now you can add your modified script to the gameobject.
     
    Slsp63 and unity_8R3gaxreN6dMTA like this.
  6. Zarkow

    Zarkow

    Joined:
    Jul 27, 2015
    Posts:
    92
    I am getting it in 2018.3.0f2, after purchasing and importing a UI-skin set.
     
  7. choxmi

    choxmi

    Joined:
    Jul 13, 2015
    Posts:
    2
    I'm using 2018.3.6f1 and I fixed this issue by unpacking the prefab. Right click on the prefab and select unpack prefab.
     
  8. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Unity 2019.
    Unity 2019.2.8f1: still getting that error.

    in debug mode I swapped one script on a prefab instance in the Hierarchy tab with a child class of that script (this usually causes no data loss since most of the fields are the same).

    First, I renamed the script (added an underscore inbetween - yes, I know, I usually don't use underscore in class names)
    The prefab broke like this:

    And the infamous "disconnecting is no longer implemented" error popped up

    So I created a child class of Puzzle_Socket, calling it Puzzle_Gear.

    I enabled Debug mode to see if my data was already there but:

    Which is weird, since I have no compile errors!

    Is it because I'm using generics?


    So, I replaced the script with the child class and, as usual, all data is still there:

    You can even see that there are a few fields marked in bold as dirty or "overriden from the prefab value"

    Notice the "+" icon, like I was trying to add a new script to the prefab, which is not true.

    Of course, since I've got many prefabs, the next step was to Apply the changes to all the instances of the prefab, but:


    The script is in no way invalid.

    Is this a new issue?

    I fear I lost all of my data used by the base class, and my last commit to the repo was hours ago :/

    Do you have any clue?
    Is script swapping being deprecated in some way? That was insanely useful to me - the only alternative I can think of is creating "migration" scripts using deep copying.

    And yet I can't figure out a single reason which makes a perfectly running script from being considered invalid.

    I already restarted Unity, but didn't change a thing.

    Any clue?

    EDIT:

    Fixed!
    Looks like I needed to open the prefab, swap the base class (for some reason marked as invalid even by reimporting it or changing it to force a recompile) with the child class, and exit Prefab mode.

    Doing it on an instance causes the above issue: you can't apply a change even if you deleted the offending script in the instance, because it has no effect on the prefab, which still contains the invalid script.
    In this case, the invalid script should have been marked for removal. Instead it just disappears from the inspector, but it only disappears from the instance, creating some confusion. [ISSUE]

    This was an instance from which I deleted the "invalid script".
    The script got hidden, and replacing in the instance the base class with the child class caused the inspector to assume it was a new component.

    As I correctly replaced the script in Prefab mode, I went back to check that instance and, surprise!
    The script has always been there, but now is correctly marked as removed from the prefab instance.
     
    Last edited: Oct 5, 2019
  9. FaatehSyed

    FaatehSyed

    Joined:
    Nov 12, 2020
    Posts:
    2
    Can you please help me? I'm new.
     
  10. Gollum99

    Gollum99

    Joined:
    Sep 22, 2020
    Posts:
    6
    another random error message , with no indication as to where the actual problem has occurred.
     
    halley and unity_8R3gaxreN6dMTA like this.
  11. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Yeah, it was left in there to determine the frequency users would report it. As expected it as rarely encountered.
    It does not actually break anything, but it means some is still trying to do stuff that would usually break the connection to the prefab assets before nesting was introduced. Usually that is people trying to change the script of a MonoBehaviour component when the inspector is in debug mode.
     
  12. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    305
    2020.1.15 and it's still in there like this. I had to google the error message to know what the hell it was talking about. Please improve the messaging.
     
  13. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    Just came up for me today - yes, better error message.
     
  14. nareshbishtasus

    nareshbishtasus

    Joined:
    Jun 11, 2018
    Posts:
    36
    Facing same issue please fix it
     
  15. vamosfa

    vamosfa

    Joined:
    May 15, 2016
    Posts:
    60
    This error is still alive and it causes my class to do not work at all
     
  16. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @vamosfa I which situations are you getting this error?
    As far as I know it should only happen if you change the script on a MonoBehaviour
     
  17. vamosfa

    vamosfa

    Joined:
    May 15, 2016
    Posts:
    60
    Thanks for replying. I can not help to reproduce the error as it is fixed by itself. I do not know why but it is not happening yet.
     
  18. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    104
    Got that on 2021.3.14f1, we need to swap unity Button to our own "ProjectButton". Seems like there is no easy way to do that without having to relink everything.

    edit: TIL you can right click the inspector tab and select "Debug". From there, you can simply change the "Script" property to your other script, in my case "ProjectButton" and it works fine! I did not search how I could batch process prefabs using this method but that just saved me!
     
    Last edited: May 4, 2023
  19. modernator24

    modernator24

    Joined:
    Apr 7, 2017
    Posts:
    201
    +1 2021.3.1f1, do the same. Replacing script in debug mode. Saving prefab doesn't change anything.