Godot 3.2.1。在刷新查询时无法更改此状态。使用call_deferred()或set_deferred()来改变监视状态。

10
在我的2D游戏中,玩家有能力摧毁装有两种碰撞形状的箱子。当销毁箱子时,会生成一些也带有碰撞形状的物品。但是当调用下面的函数时,Godot控制台中会显示许多类似的错误信息。
代码:
func _on_Crate_item_dropped(collectible, pos):
    collectible.init(pos, Vector2(rand_range(30, 100), rand_range(-10, 10)))
    $CollectibleContainer.add_child(collectible)  # error occurs here

错误:
ERROR: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.
1个回答

13
方法call_deferred()会在空闲时间调用对象上的方法。它的第一个参数是方法名称字符串,其他参数是方法的参数。
$CollectibleContainer.add_child(collectible)

$CollectibleContainer.call_deferred("add_child", collectible)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接