novemberdev_object_pooling_godot icon indicating copy to clipboard operation
novemberdev_object_pooling_godot copied to clipboard

Issue with object pool when destroying objects sometimes.

Open Kontrano opened this issue 3 years ago • 1 comments

Hi i love your object pool and am using it to great effect but I seem to have encountered a bug or I'm doing something wrong,

But when kill a node and call the ObjectPooling.queue_free_instance(self) command it sometimes gives the error :

Invalid set index "global_transform ( on base: "Area2D ( Asteroid_new.gd)) with value of type Vetor2,

If i comment out the commented out the if instances is Node2D: part i don't get this error and all seems to be working fine for now, but I'm not fully sure what that bit of code does and how to otherwise fix this bug. Would you know what the problem is?

`func toggle_instance_activation(instance, activate): recursively_activate(instance, activate) if instance.has_method("on_object_pooling_reset"): instance.on_object_pooling_reset(activate) if !activate: instance.get_parent().call_deferred("remove_child", instance)

	if instance.has_meta("scene_path"):
		if instance is Spatial:
			instance.global_transform = object_pool[instance.get_meta("scene_path")].props.transform
		
		if instance is Node2D:
			instance.global_transform = object_pool[instance.get_meta("scene_path")].props.transform
			pass
		if instance is Control:
			instance.rect_global_position = object_pool[instance.get_meta("scene_path")].props.position
			instance.rect_rotation = object_pool[instance.get_meta("scene_path")].props.rotation
			instance.rect_scale = object_pool[instance.get_meta("scene_path")].props.scale
			instance.rect_size = object_pool[instance.get_meta("scene_path")].props.size
instance.visible = activate`

Kontrano avatar May 12 '22 21:05 Kontrano

Apparently code blocks are not working correcly for some reason but hopefully its readable

Kontrano avatar May 12 '22 21:05 Kontrano