Search Unity

Runtime Prefab material updates its changes to prefab definition

Discussion in 'Prefabs' started by unitylepi, May 4, 2020.

  1. unitylepi

    unitylepi

    Joined:
    May 21, 2018
    Posts:
    34
    Not sure this is a bug but in general the settings you change in the inspectors during run/debug, don't make their way into your project settings, but I found that If I create a prefab instance in code, then any changes I make to its materials in the inspector during debuging, directly affect that material and the prefab even on the next run.

    Feels kind of dangerous because you always assume you automatically undo all test settings after the debug session ends, but maybe materials aren't changed in memory but directly on disc?
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Hi,

    It depends on how you access the material. The sharedMaterial property is a reference to the material on disk.
     
  3. unitylepi

    unitylepi

    Joined:
    May 21, 2018
    Posts:
    34
    Hmm, I'm setting the albedo of the shader component in the inspector of a skinned mesh renderer of a runtime instantiated prefab.
     
  4. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    The material shown in the inspector is the sharedMaterial. By that I mean that is the asset on disk and if you change this in the inspector all objects using this material will change.
     
  5. unitylepi

    unitylepi

    Joined:
    May 21, 2018
    Posts:
    34
    Thanks, that's really good to know.

    If I access the shared material of a skinned Mesh Renderer of a prefab through code, does that also mean the material changes on disk?
     
  6. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639