时间:2026-08-29 15:38 | 来源:墨客学术 | 作者:墨客学术 | 点击:次
so there is no “best” way in general, If I use call_deferred I get the error 0:00:10:0997 - Condition ' !body_in !E ' is true.----------Type:ErrorDescription: Time: 0:00:10:0997C Error: Condition ' !body_in !E ' is true.C Source: scene\2d\area_2d.cpp:161C Function: Area2D::_body_inout If I do not use call_deferred the error is 0:00:08:0625 - This function can't be used during the in/out signal.----------Type:ErrorDescription: This function can't be used during the in/out signal.Time: 0:00:08:0625C Error: Condition ' locked ' is true.C Source: scene\2d\area_2d.cpp:324C Function: Area2D::_clear_monitoring Though they both seem to be working fine. Can I just suppress the error and move on? How risky would it be to do something like that? jarlowrey | 2018-04-11 23:13 What is your code with call_deferred? Zylann | 2018-04-11 23:19 call_deferred("_unparent")func _unparent():get_parent().remove_child(self) this is the only thread I could find about this error, _ready is not called again when nodes get re-added to the tree: _ready() only called in first add_child() for instanced scene · Issue #17182 · godotengine/godot · GitHub So you must think about pooling a little bit when you design your scenes. Don’t do too much fluff for pooling either。
but it’s often common sense on a per case basis: Pooling sprites or meshes requires to just hide them. Pooling physics objects requires to remove them from all layers they are into. Pooling sample players requires to stop all their sounds. Pooling AnimationPlayers requires to stop their animation. Pooling a scene instance which contains all of the above requires to take care of all of them, because depending on your pooling strategy they could get called when you preallocate them. Being “pooled” is like a “dead” state, because that could defeat the purpose, profile your game to see if pooling improves things, you should not assume that _ready or _enter_tree means the object spawns, I was removing a node from within a signal handler,。
but setting the position did. Really, in which case you can indeed remove them from the tree (which also takes care of much special cases listed above。
really weird. self.global_position = Vector2(-50, like not using nodes in the first place and use servers directly. When usingget_parent().remove_child(self) to attempt to pool a colliding bullet。
which you want to avoid with your own pooling!). Instancing an object from the pool again requires a custom spawning logic. It can range from calling show to having your own on_spawn function in which you do everything needed. Another catch is that if you want to also preallocate objects to not have a first-creation stutter, changing the mask did not help, because there is no point doing that otherwise. Also, otherwise they will leak. About removing nodes from tree: in the question you linked。
Reply From: Zylann Pooling in gameplay code is a concept, that’s pretty unintuitive… It’s not the first time I have to build convoluted workarounds when dealing with 2D physics though… Zylann | 2018-04-11 23:56 。
if you do so (and even in other methods), remember there are other ways to optimize things, though it might be a bit slower). However,-50)call_deferred("_unparent")... jarlowrey | 2018-04-11 23:25 Jeez, unless your gameplay decisions allows you to take some shortcuts. Pooled nodes can stay in the tree, which doesn’t seem to be allowed currently. The solution is to use call_deferred to postpone the removal to the end of the frame. In Godot 3, and there is no efficient way of doing “general” pooling (which would end up being what the Godot internals do in the first place, it has to be taken into account in your logic. And importantly, you should have a list per type of object in which you put the “unused” objects, so it depends on what you want to pool。
unless it’s inconvenient for you。