Skip to content

feat: RewindableState signals#494

Merged
elementbound merged 10 commits intofoxssake:mainfrom
RickyYCheng:main
Sep 27, 2025
Merged

feat: RewindableState signals#494
elementbound merged 10 commits intofoxssake:mainfrom
RickyYCheng:main

Conversation

@RickyYCheng
Copy link
Copy Markdown
Contributor

@RickyYCheng RickyYCheng commented Aug 21, 2025

I think adding three signals, state_enter, state_tick, and state_exit, for the leaf states of the state machine would be a great choice.
This has several benefits:

  1. When state scripts do not need to be reused, we can avoid script bloat—no need to create a bunch of scripts.
  2. If all signals are in one script, the same context can be shared.
  3. It does not change the existing API.

Some repositories already do this, such as godot_state_charts.

Through Discord discussions, add the RewindableState._prevent_transition field and RewindableState.prevent_transition() to RewindableState to deny state entry.

It's not entirely clear how to change can_enter to achieve this. However, this can be done by executing prevent_transition for next_state in state_exit. The same applies to overriding exit.
This might change our expectations for can_enter. If overriding users also use prevent_transition, they don’t actually need to override can_enter.

Besides, I suppose there is no need for sync-ing _prevent_transition field since will reset it to false each transition.
And this field is not accessible in tick.

Finally, this change is fully C# compatible.

@elementbound elementbound changed the title Feature Request: Add signals for RewindableState feat: RewindableState signals Sep 27, 2025
Copy link
Copy Markdown
Contributor Author

@RickyYCheng RickyYCheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

@elementbound elementbound merged commit 9883f3f into foxssake:main Sep 27, 2025
2 checks passed
@elementbound
Copy link
Copy Markdown
Contributor

Thanks and congrats on the contrib @RickyYCheng 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants