8000
Skip to content

LLM cannot be initialized from an editor script: DontDestroyOnLoad in Awake() #412

Description

@merrymaker14

Describe the bug

Describe the bug

LLM.Awake() calls DontDestroyOnLoad, which Unity forbids outside Play mode. This makes it
impossible to initialize an LLM from an editor script.

The model itself loads and the server starts — the console shows model loaded — and then
Awake() throws:

InvalidOperationException: DontDestroyOnLoad can only be used in play mode and, as such,
cannot be part of an editor script.
LLMUnity.LLM.Awake () at Assets/LLMUnity/Runtime/LLM.cs:365

Because the exception interrupts Awake() before the native caller is created, every request
afterwards fails with LLM caller not initialized.

Why this matters

I'm building editor tooling that lets a developer verify their setup — model present, correct,
and actually producing a reply — without entering Play mode. The rest of my stack (speech
synthesis, model management, validation) works fine from the editor; this is the only thing
that blocks the dialogue half.

Suggested fix

Guarding the call would be enough:

if (Application.isPlaying) DontDestroyOnLoad(transform.root.gameObject);

Alternatively, expose it as the serialized setting that #152 already suggested — "This could
also be a setting in the component itself"
— which covers both cases and changes the default
behaviour for nobody.

To be clear: I understand DontDestroyOnLoad was added deliberately (#152, #174) and I'm not
asking for it to be removed. Only for it to be skippable when it cannot legally run.

Steps to reproduce

No response

LLMUnity version

3.0.3

Operating System

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0