Use call_deferred() or set_deferred() to change monitoring state instead in c#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By daniel500013

Hi, I want to create a script in which when I am in the selected position, my door will open, and after leaving this area the door was closed, so I tried to do it using area2d, but when my character enters my area, I have an error like in title and someone can tell me how to fix it?


Texture green_line = (Texture)ResourceLoader.Load("res://Ship/Ship_Elements/Textures/greenLine.png");
Texture red_line = (Texture)ResourceLoader.Load("res://Ship/Ship_Elements/Textures/redLine.png");

private void _on_enter_area_body_entered(object body)
    CollisionShape2D line_collider = GetNode<CollisionShape2D>("StaticBody2D/CollisionShape2D");

    Sprite line = GetNode<Sprite>("Sprite");
    line.Texture = green_line;

    line_collider.Disabled = true;
:bust_in_silhouette: Reply From: Jason Swearingen

It seems like you are calling this from a different thread and the engine detects/complains when that happens.

see this page’s “Scene Tree” section for how to use call_deferred() to do what you want.