Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FrayCompoundState : change ready ordering for substate #86

Open
Remi123 opened this issue Jan 30, 2024 · 2 comments
Open

FrayCompoundState : change ready ordering for substate #86

Remi123 opened this issue Jan 30, 2024 · 2 comments

Comments

@Remi123
Copy link

Remi123 commented Jan 30, 2024

Welcome back.

Didn't play too much with new features yet, but I appreciate the get_node function. Reduce my code size by a lot.

here is my change for the ready function :

func ready(context: Dictionary) -> void:
	if not context.is_read_only():
		context.make_read_only()
	_ready_impl(context) # <--- new emplacement
	for state_name in _states:
		var state: FrayState = _states[state_name]

		if state is FrayCompoundState:
			state.ready(context)
		else:
			state._ready_impl(context)
        #_ready_impl(context) # <--- Changed ordering

I use _ready_impl to create new states and keep things together in the code.

Substate are created in _ready_impl, then each of them are made ready afterward.

Thank you

@Pyxus
Copy link
Owner

Pyxus commented Feb 15, 2024

There is a _enter_tree_impl method which is invoked when a state is added to the hierarchy. You should be able to create new sub-states within this... That is unless you're using the context as part of your setup. Though i'd argue the sub-states could just read from the context themselves.

Let me know your thoughts. I'm not opposed to changing the ready order since, at this moment, I don't see any downsides to readying the parent then the children. I just don't believe this change is necessary for what you're trying to do.

Edit: Wanted to add I think i'll note your approach in the documentation. I hadn't considered building states within states.

@Remi123
Copy link
Author

Remi123 commented Feb 16, 2024

I tried the _enter_tree_impl, however at this point not all nodes are ready, so I am missing some content when initialized. Then it become fighting my node tree order of initialization..

I tried to fixes this by modifying the _ready part, and it work correctly so I'm quite happy with this.

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

No branches or pull requests

2 participants