- Edited
Hi, relatively new to godot here. As I've gone through a few tutorials in regards to Godot and GDScript I have seen a lot of references when changing the state of Collision to use
set_deferred("disabled", true)
And similar code.
However, in practice I always get it to set 'disabled' to false.
Example code that I'm using it in (Apologies about possibly unusual formatting... I find it's what makes it best for me to organize):
onready var collision = $StaticBody2D/CollisionShape2D
export (bool) var enabled_on_start = false
# Called when the node enters the scene tree for the first time.
func _ready():
checkIfEnabledOnStart()
func checkIfEnabledOnStart():
if enabled_on_start:
enableArea()
else:
disableArea()
print(collision.disabled)
func enableArea():
collision.set_deferred("disabled", false)
print("Area Enabled")
func disableArea():
collision.set_deferred("disabled", true)
print("Area Disabled")`
However, I get the following output from the print statements from 2 objects each with enabled_on_start
set to true/false respectively:
Area Enabled
False
Area Disabled
False
This is a recurring theme anytime I've tried using set_deferred(), and as such for now I'm just setting disabled
manually, but from what I gather that can have unexpected collision consequences.
If there's something obvious I'm missing I'm all ears, because everywhere I have looked they say simply use set_deferred
as I'm using it here.
EDIT: While the print statements might be getting called in the same frame, and therefore aren't accurate. However, the collision when I go to interact with the object IS solid.