You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
extends KinematicBody2D
var global_col: KinematicCollision2D
var dir := Vector2.RIGHT * 2
func _physics_process(delta: float) -> void:
var col := move_and_collide(dir)
if col:
dir.x = -dir.x
if not global_col:
print("------------------------")
global_col = col
if global_col:
print(global_col.collider.name)
You can clearly see that global_col is assigned only once (------ indicates it) and from a local variable. However every time col gets a new value, global_col is modified too. AFAIK that's not how references work.
EDIT:
Ok, for whatever reason KinematicBody2D reuses and returns the same collision every time. Any reason it's like this? It should at least return a duplicate.
The text was updated successfully, but these errors were encountered:
You mean that whatever is returned by move_and_collide() is the same internal reference to KinematicCollision2D somewhere within KinematicBody2D? If that's the case perhaps that's due to performance reasons.
It would be nice to have KinematicCollision2D as a property then, or adding a method which can retrieve this reference outside of the move_and_collide() call, something akin to get_collision() similarly to get_slide_collision(), and perhaps is_colliding() as in a raycast.
You mean that whatever is returned by move_and_collide() is the same internal reference to KinematicCollision2D somewhere within KinematicBody2D?
Yes. At first I thought it's some bug related to references, but the returned collision is the same object actually.
If that's the case perhaps that's due to performance reasons.
The collision is a simple struct, so I doubt it's about performance. It might just be needed somewhere else, but still, the returned collision should be unique. So duplicating it on demand would be a good idea IMO.
Godot version:
3.2 and 7724b84
Issue description:
Look at this code:
You can clearly see that
global_col
is assigned only once (------ indicates it) and from a local variable. However every timecol
gets a new value,global_col
is modified too. AFAIK that's not how references work.Minimal reproduction project:
TestProject.zip
EDIT:
Ok, for whatever reason KinematicBody2D reuses and returns the same collision every time. Any reason it's like this? It should at least return a duplicate.
The text was updated successfully, but these errors were encountered: