Search Unity

Perform actions in the editor without freezing it?

Discussion in 'Scripting' started by Ardenian, Dec 3, 2019.

  1. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    I have a very time-consuming task that I execute in the editor in Edit Mode using a context menu. This freezes my editor and I wonder how I can perform an action in the editor, like calling a function, that runs in the background taking performance and resources, but not freezing the editor because it doesn't have to complete in a single frame update.

    I know of Coroutines using the
    yield
    keyword allowing such a behavior, but if I read the manual correctly, I always need a GameObject that the coroutine is attached to. Is there no way to perform something in the editor without having to attach it to a GameObject or a MonoBehavior instance? I would like to not create a dummy GameObject for the purpose of having a coroutine.

    What is a recommended way to perform (automated) actions in the editor that should not be forced to complete in a single frame update and therefore not freeze the editor?
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Ardenian likes this.
  3. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    Thank you very much, @eses, that looks exactly like what I am looking for!