Collision shape and process_mode cant work togheter ?!?

Godot Version

4.4

Question

hello,
I have an enemy with 5 states… idlePatrol, idleAlert, shoot, pain, dead

when i change states i use ““set_process_mode”” to enable / disable the node states, and change the collisionBox and hurtBox shape using these functions

func _changeNode_FromTo( from, to ):
	from.set_process_mode(Node.PROCESS_MODE_DISABLED)
	to.set_process_mode(Node.PROCESS_MODE_INHERIT);
	velocity.x = 0;
	skel.anim_delayReset = true;
	$Timer.stop();
	skel.animPlayTimes = 0;

@onready var colBox = $collisionBox;
@onready var hurtShape = $direction/hurtBox/hurtShape

func _changeCollision( posY, sizeX, sizeY ): # on hold
	colBox.position.y = posY;
	colBox.shape.size.y = sizeY;
	hurtShape.position.y = posY;
	hurtShape.shape.size.x = sizeX;
	hurtShape.shape.size.y = sizeY;

ive printed the ““get_process_mode()”” in all nodes and… actives ones are 0 disabled ones are 4, so everything is correct

but i cant change the collision and hurtbox shape ?!?
if i use this on idlePatrol: _guard01._changeCollision(-90, 30, 180); # standing everything goes to hell ?!?

If i change the collision on the state node shoot, for shooting down_guard01._changeCollision(-64, 30, 128); # crouching, the collisionBox makes the enemy standing in the air ?!?

This only happens if i use “”_changeCollision"" in ““idlePatrol””… all the other states i can change the collision without any problem…

Does the ““func _process(_delta: float)”” is still running if PROCESS_MODE_DISABLED ?
Is this happening because ““idlePatrol”” process is set to inherit by default ?

Ive searched for hours and dont have anything in the code that messes with the nodes ““collisionBox”” and ““hurtBox shape””

should i make MRP… wth can we never change collision boxes in godot ?! something always goes wrong

It sounds like you are changing the collision shape in _process? You shouldn’t adjust physic properties in _process as this can cause a de-sync with the physics server.

Have you tried running your code in _physics_process instead?

1 Like

I dont think it makes any diference…
Ive even made a new project with node states… idlePatrol, idleAlert, shoot, pain, dead

and change the collision in ““func _process”” and everything worked, the character doesnt stay on air when i change it to ““shoot””

################---------shoot node -------#############

func _process(_delta: float) -> void:
	plr.spr.texture = plr.txtDN
	plr._changeCollision(-18.25, 37.5);
	
	
	if ( Input.is_action_just_pressed("key_3") ):
		plr._changeNode_FromTo(plr.shoot, plr.idlePatrol)
		return

################---------player ( plr ) -------#############

func _changeCollision( posY, sizeY ):
	colBox.position.y = posY;
	colBox.shape.size.y = sizeY;


func _changeNode_FromTo( from, to ):
	from.set_process_mode(Node.PROCESS_MODE_DISABLED)
	to.set_process_mode(Node.PROCESS_MODE_INHERIT);

it seems iam going to have to comment/delete all my code, to find out what is going on… Iam never going to get rid of this and finished it :frowning:

thanks it worked ive changed it to:
func _physics_process(delta: float) -> void:

and the character no longer stay in air when going into the next "NODE state " with a diferente collision shape size… this is impossible to trigger… has changing the code doesnt do anything, its like “_process” is running way ahead of the code,
has the character only goes to the previous state when the frame reaches 4…

***** shoot node *****

		stGetUP:
			skel._playAnim( _guard01.animCrouchOUT, 0.1, false );
			if ( skel.animFrame == 4 && skel.nextFrame == true ): #### only when frame is 4 but collision is already another and the character is in the air
				stateShoot = skel._changeState(stShootExit);
				
				
		
		stShootExit:
			_setAreaUPDN(false);
			_setArea(false);
			_guard01._changeNode_FromTo(_guard01.shoot, _guard01.idleAlert ); ###--going to node2D idleAlert 
			#_guard01.idleAlert.stateAlert = _guard01.idleAlert.stWalk;

when the character is in state ““stGetUP”” the collision shape size changes to the collision shape size in "idleAlert " then it changes back to the collision shape size in “shoot”

its really strange because iam not using ““physics”” for anything…???.. just changing from one NODE to another by using:

set_process_mode(Node.PROCESS_MODE_DISABLED)
set_process_mode(Node.PROCESS_MODE_INHERIT);

[edit]
never mind it still doesnt work… when i get all states running togheter, the character stay in the air again…
changing the collision shape only work with 2 nodes, once there are 3 nodes being used the shape no longer changes… collisions are all screwdUp

found the problem…
I have about 5 enemies duplicate in the level… for some reason i think they are all sharing the same collision shape…

If i only use 1 enemy it works normally
If there a way to set a collision Shape2D unique to that instance ?
In code or any other way ?

Since in the editor when i duplicate the enemy they all work correctly execpt for the shape inside collision 2d node ?

fix


@onready var colBox = $collisionBox;

func _ready() -> void:
	colBox.shape = colBox.shape.duplicate()
1 Like

Glad you figured it out!

FYI, you can also do the same from the inspector by checking Local to Scene

1 Like

ho ok… just tried it and it works, thanks
it works the same has the code in ready func, but the editor is better less code the better