Search Unity

(Case 1108062) Cannot remove "Missing Script" Component from Prefab

Discussion in 'Prefabs' started by Peter77, Dec 9, 2018.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    2018.3 is unable to remove a Component from a Prefab, where the Component Script is missing. Trying to remove the missing Component outputs the following error to the Debug Console:

    Reproduce
    1) Open attached user project
    2) Select "Assets/Item_AmmoBox.prefab"
    3) Click "Open Prefab" in Inspector
    4) Right-click "(Script)" and select "Remove Component"
    5) Observe it displays "Saving failed" error dialog, click OK
    6) Leave prefab edit mode by clicking the "<" button in the Hiearchy
    7) Click "Save" in the "Prefab Has Been Modified" dialog

    Actual
    Unity displays "Saving failed" and the Components with missing Scripts can't be removed.

    Expected
    Being able to remove Components whose Scripts are missing.
     
    LeonhardP likes this.
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
  3. dontdiedevelop

    dontdiedevelop

    Joined:
    Sep 18, 2018
    Posts:
    68
    OlegPavlov likes this.
  4. Deleted User

    Deleted User

    Guest

    There is a workaround:
    1. drop the prefab in the Hierarchy view,
    2. in the inspector for the prefab that you just dropped on the scene, remove the components you need to be removed,
    3. override the changes in the prefab.
    It's not perfect but it will allow you to wait until the problem has been fixed.
     
    muhamad1987 likes this.
  5. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Still not fixed in Unity 2019.1?

    I upgraded a project and I'm unable to remove a missing script from a prefab. The workaround suggested above here was what I attempted first as that was the most intuitive way, but I'm not allowed to override the prefab because it tells me I'm not allowed to apply the changes when I have an invalid script (which I'm trying to remove).

    This is ridiculous. What is this "feature" attempting to safe guard me from doing? I'm attempting to fix my prefab, but it's actively preventing me from doing this.

    I had to delete my prefab and all instances of it and recreate it from scratch.
     
  6. Deleted User

    Deleted User

    Guest

    I tried in a brand new project:
    1. dragged a sphere on the scene,
    2. created a script and added it to the sphere,
    3. made the sphere a prefab,
    4. placed several instances of the sphere in the hierarchy view,
    5. deleted the script, in order to create the "missing script",
    6. opened the prefab,
    7. removed the script,
    8. the script was removed from all the existing objects on the scene as well.
    I remade the experience but this time, after placing several instances of the prefab in the hierarchy view:
    1. deleted the script, in order to create the "missing script",
    2. selected all the instances of the prefab in the hierarchy view,
    3. removed the missing script,
    4. as happened to you, I wasn't able to override the prefab, but...
    5. the missing script went away by itself after I lost the focus on Unity, because I was writing this post.
    It seems that the prefab fixed itself after all.

    Anyway, it seems that the right way is removing the missing script in the prefab instead of doing it in the instances of the object.
     
  7. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    No idea. Didn't work for me. The missing script was part of the old post processing stack which is now built-in to HDRP so I deleted the package after I upgraded the project, but I was unable to remove the post processing script from my camera.

    Will keep an eye out if happens again.

    But HDRP doesn't seem to interact well with the new prefab system in general. The camera and light data components that are automatically added to cameras and lights are added multiple times and show up as overrides for the prefab etc.
     
  8. barbelot

    barbelot

    Joined:
    Jul 18, 2017
    Posts:
    38
    I have a similar problem where adding a HD Camera to a prefab always create a missing script which then cannot be removed.

    To reproduce :
    1. Create a camera in your scene (with HDRP this automatically add the HD Additional Data script to it).
    2. Create a prefab from this camera.

    The prefab will be created with a missing script that cannot be removed. The camera in the scene will also now have two HD Additional Data scripts on it with one greyed out and marked as removed.

    upload_2019-5-2_14-50-5.png
     
  9. Doomlaser

    Doomlaser

    Joined:
    Dec 9, 2013
    Posts:
    24
    what the heck... I'm on 2019.1.6f1. I have a prefab with a missing script apparently. It tells me I can't override, enter Prefab mode. I find and remove the script -- on a Camera -- and it can't save, I get this same error as the OP:

    "You are trying to replace or create a Prefab from the instance 'portal camera' that references a missing script. This is not allowed.
    Please change the script or remove it from the GameObject"

    Rermoving it from the GameObject throws this error! I'm trapped!
     
    Last edited: Nov 5, 2020
  10. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @Doomlaser

    Can you please file a bug report with a small project that reproduces the issue
     
  11. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    I'm still able to reproduce this issue in the currently latest 2018 LTS build.

    I submitted the following bug-report with Unity 2018.4.3f1:
    (Case 1167814) 2018.4: Cannot remove missing Script Component from Prefab

     
  12. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
  13. B1QQ

    B1QQ

    Joined:
    Aug 16, 2018
    Posts:
    10
    not fixed in 2019.1.10f1
     
  14. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    Have you found the "Resolution note" from the bug-report?
    https://issuetracker.unity3d.com/issues/cannot-remove-missing-script-component-from-prefab
     
  15. Rayeloy

    Rayeloy

    Joined:
    Feb 12, 2017
    Posts:
    45
    not fixed in 2019.2.12f1
     
  16. Sam_Space

    Sam_Space

    Joined:
    Jun 28, 2019
    Posts:
    16

    Tried this method on 2018.4.3 and it worked out. However I noticed the error really came from an object I was trying to child to the parent prefab object. The object had a script that was declared missing. I tossed the script component and that worked out.
     
  17. JacobSchwitzer

    JacobSchwitzer

    Joined:
    Jul 19, 2018
    Posts:
    1
    Hey, my team and I had this error for the last week and this forum helped us find a solution that also works. We created a new prefab from the previous one, removed the missing scripts, reattached them, replaced the old prefab with this new one in scene, and then deleted the old one. I hope this helps anyone else who stumbles onto this!
     
  18. Beerfootbandit

    Beerfootbandit

    Joined:
    Aug 18, 2017
    Posts:
    4
    Don't 'open prefab'. Instead:
    1: drag the prefab to the hierachy
    2: right click it and choose unpack(not unpack completely)
    3: delete stuff or remove scripts with errors
    4: make sure ALL scripts thats causing the errors are gone before 5: put the gameobject back in the project to make it a prefab again. or simply apply the chan

    I don't understand the open prefab thing atm. All I know is unpacking the prefab to modify it is the closest thing to the good old Unity 2017

    I hope this helps.
     
    Last edited: Jun 11, 2020
    _eternal likes this.
  19. blackstaffgames

    blackstaffgames

    Joined:
    Jul 10, 2014
    Posts:
    19
    To follow on from this. Is there a way to identify which prefabs have the missing script in?

    "You are trying to replace or create a Prefab from the instance 'SomeScript' that references a missing script. This is not allowed.
    Please change the script or remove it from the GameObject."


    Get this everytime I call AssetDatabase.saveassets. I have loads of prefabs and no idea which one contains the missing script and no way to identify to remove it. Not a manjor issue but frustrating to have an error called in editor everytime theres an update.
     
  20. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    304
    Thanks, this worked for me (2020.3.14).

    I use an editor script that's based on the one in this answer: https://answers.unity.com/questions/1372755/missing-script-after-build-but-no-referenced-gameo.html

    Very handy to keep this around.