Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Making data persist from Edit Mode to Play Mode?

Discussion in 'Editor & General Support' started by _eternal, Nov 9, 2018.

  1. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    116
    I have a script tagged with the [ExecuteInEditMode] attribute which periodically does stuff while I'm working. I'm trying to keep track of what methods the script has called by keeping a list of ints that correspond with what the script is supposed to do. However, the list is getting cleared whenever I enter play mode. Is there any way to make the data persist from Edit -> Play? It's okay if changes made during Play mode get reset when returning to Edit.
     
  2. GameDevCouple

    GameDevCouple

    Joined:
    Oct 5, 2013
    Posts:
    2,423
    You likely setup the list in start or awake, which will clear it.
     
  3. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    116
    Hmm, strange... that wasn't the problem (the list is only initialized on editor startup, like this). But it seems to be working now. It might have had something to do with prefab defaults, because I tried typing in various values in the inspector, and it worked — then I tried letting the editor script modify the values on its own, and suddenly it worked as well. It's a mystery!
     
unityunity