Skip to content

[Question] Is there a way to safely Wait/Delay execution in REPL and startup.cs? #91

@Lusiiky

Description

@Lusiiky

Hello,

For context, I am currently with a game built on Unity 6000, using a MelonLoader nightly build (IL2CPP), and the latest version of UnityExplorer.

My goal is to execute a command, wait for a few seconds (or wait for a scene to reload), and then execute another command. For example: calling a RestartGame() method, waiting for the new scene to load, and then modifying a newly spawned manager.

However, I've hit a wall trying to implement a delay inside the REPL / startup.cs evaluator:

  1. System.Threading.Thread.Sleep(5000) freezes the Unity Main Thread entirely, so the game never actually loads the new scene during the wait.
  2. Task.Delay().ContinueWith(...) throws a System.InvalidOperationException: The current SynchronizationContext may not be used as a TaskScheduler error in the REPL.
  3. Trying to wrap the code inside a local function, a class, or an IEnumerator (to use WaitForSeconds or MelonCoroutines) results in Mono Evaluator syntax errors like error CS1525: Unexpected symbol or error CS0201. The evaluator seems to strictly process top-to-bottom flat statements.

My questions:

  • Is there a built-in UnityExplorer method or a specific REPL syntax trick to achieve a non-blocking wait/yield inside startup.cs?
  • If not, would it be possible to consider adding a built-in UE helper for this in the future? (e.g., something like UnityExplorer.Wait(5f, () => { /* code */ }); that handles the Coroutine safely behind the scenes).

Thank you for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions