How to get back physics when using call_deferred?

Godot Version

4.2.2

Question

I keep getting this problem and have no clue how to fix it. Do I use set_deferred after everything?

What is the problem? What do you want to happen?

You have every item rotating towards the mouse with each input (often), then you move the look at into _on_player_entered so it only rotates once, when the player enters.

I only want to look_at mouse with the item on the player not all of them.

Maybe the easiest trick, since I do not have your player script, would be to only enable the _input processing once picked up. But doing look_ats on the player would be better, depends on how you intend to build out these items, try it out I guess :upside_down_face:

func _ready():
    set_process_input(false)
    # etc...

func _on_player_entered(body):
    if body.has_empty_slot():
        set_process_input(true)
        # etc...

That was a good idea, I tried to do that before just not on the player’s script but it still did not work. Here’s the players script if you see anything sweet if not thank you anyways.

extends CharacterBody2D

@onready var hand = $pivot/hand
@onready var fx = $pivot/FX
@onready var hotbar = $UI/Hotbar

func _ready():
	set_process_input(false)

func _physics_process(_delta):
	
	$pivot.look_at(get_global_mouse_position())
	
	velocity = Input.get_vector("left","right","up","down") * 200
	move_and_slide()
	
func play_FX(skill):
	fx.play(skill.name)
	
func add_item(stats,skill):
	hotbar.add_item(stats,skill)
	
func has_empty_slot():
	return find_child("Weapons").is_available()

This is the item script. I tried the set_process_input on both item and player

extends Sprite2D

@onready var collision = $Area2D/CollisionShape2D
 
@export var stats : Item
@export var skill : Skill

func _ready():
	set_process_input(false)
	if stats != null:
		texture = stats.icon
		
func _on_player_entered(body):
	if body.has_empty_slot():
		call_deferred("reparent",body.find_child("Weapons"))
		position = body.position
		body.add_item(stats,skill)
		collision.call_deferred("set_disabled",true)
		set_process_input(true)

given these two scripts set_process_input will do nothing, it only disables a func _input(event): override. Neither script has one, but in the video the Item did.

1 Like

lol I didn’t even see that. Thank you that actually works perfect.