State machine and reusing state.gd a lot

Godot Version

4.3

Hi!

I am using state machine for my player states, also substates for those states. And as for now it works like a charm!.
I now wanted to use it for my weapon rig. I know later I will use state machine for enemies and probably meta game states itself.

all states extends state.gd node

class_name State
extends Node
signal transition(_new_state_name: StringName)
func enter() -> void:
	pass
func exit() -> void:
	pass
func update(_delta: float) -> void:
	pass
func update_physics(_delta: float) -> void:
	pass

I start to worry that there will be moment where this might start causing some unexpected error when few states will change at once. Is there a reason I should be worried?
Should I create another state.gd for enemies and / or weapons so that those don’t collide with each other?

thank you!

What would be different about the EnemyState.gd or WeaponState.gd? Extending this class does not affect the base class.

1 Like

Nothing different about it! I just try to wrap my head around how it works exactly.
What I try to ask is if extending base State.gd enough times with enough traffic in code might actually effect each other states in some way. recently learnt about race hazard in coding and I know I am far from having such problem, still it seems like this might be root for such problem in future

Large inheritance trees can be tough to wrap your head around, but if most of them come from this one State.gd script then it should be easy to trace. Race conditions are fairly rare on a single thread like Godot’s scripts are, and if you do hit a race condition it should be easy to un-roll.

Thank you :slight_smile: then I’ll continue as is