Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Editing at Gameplay keeps effect after pressing Stop

Discussion in '2020.2 Beta' started by OfficialHermie, Jul 19, 2020.

  1. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    Hello!

    In older versions of Unity, I would hit play, and then I could test new values in the Inspector.
    For example, I could change Material values to test them.

    When I then stopped the gameplay, the values would switch back to what they were before I pressed Play.

    This was a great way to test things out.
    And it was riskless as the value would revert when the gameplay was stopped.

    Now when I change material settings during GamePlay, they stay.

    Is that intended? Can I disable that?
     
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    When editing the actual Material asset in the project the changes were never reverted after stopping play mode (at least since Unity 5.0, which was the first version I tried)
     
    AlkisFortuneFish and Peter77 like this.
  3. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    I'm pretty sure it doesn't matter if you're in play mode or not if you're editing an asset - however, changes to objects in the hierarchy (not including prefab contents, which is editing an asset) do get reverted ..in my experience.

    What you could do is clone the Material and edit the instance all you want during play mode for testing. i.e. for a MeshRenderer with a single material..
    Code (CSharp):
    1. Material _materialInstance;
    2. void Start()
    3. {
    4.   MeshRenderer ren = GetComponent<MeshRenderer>();
    5.   _materialInstance = new Material(ren.sharedMaterial);
    6.   ren.sharedMaterial = _materialInstance;
    7. }
    8. void OnDestroy()
    9. {
    10.   DestroyImmediate(_materialInstance);
    11. }
    12.