Register Scratch event threads in Visual Scripting#333
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| using (var flow = Flow.New(reference)) | ||
| { | ||
| var routine = RunEventCoroutine(flow, args); | ||
| ScratchUnitUtil.StartScratchCoroutine(flow, routine); | ||
| } |
There was a problem hiding this comment.
Avoid registering scratch threads on every Update tick
In OnKeyPressedUnit.TriggerWithThreadRegistration the coroutine is always passed to ScratchUnitUtil.StartScratchCoroutine before RunEventCoroutine has a chance to evaluate ShouldTrigger. Because StartScratchCoroutine registers the coroutine with FUnityScriptThreadManager, an entry is added to m_ScratchThreads on every Update event even when no key is pressed (i.e., ShouldTrigger returns false). This creates an unbounded collection of idle thread registrations and stop-block targeting becomes inaccurate during normal gameplay, since most frames will register a new “thread” that immediately exits.
Useful? React with 👍 / 👎.
Summary
Testing
Codex Task