Search Unity

Feature Request Support replacing script in editor

Discussion in 'Editor & General Support' started by Thaina, Feb 21, 2023.

  1. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,164
    Like replacing prefab, unity should allow replacing script. For that we could make script v1/v2 that functionally the same or have similar interface but differ in some internal mechanism

    Many script could have vary inner working with the same serialization data. So when we want to switch component but still kept the same data which become tedious to copy value one by one
     
  2. euden_one

    euden_one

    Joined:
    Apr 4, 2022
    Posts:
    33
    You can put the inspector in Debug mode, then you can swap a script with another.

    The fields with the same serialization will be preserved. This is useful for inheritor classes, since they already share the same serizalization.
     
    Thaina likes this.
  3. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,164
    I see. this behaviour is possible but very hidden. Thank you very much
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Just some minor caution that I've done this before, in older versions of the editor, and ended up with some unexpected behavior. I don't have any specific test case to present, or even much memory of what happened, but I think at some point the component "broke" on that object after I replaced the script in this way. So, I guess I'd like to confirm this is fully supported behavior, and not just some kind of hacky approach that mostly works, but will have some subtle problems with it. Anyone know if this is documented as a valid approach?
     
    Thaina likes this.