How to use a KinematicCollision.Collider as a [Node] and not as an [Object] in c#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MajorBarnulf

Hi and thank you for your attention, I am still a beginner in c# so please don’t hesitate to tell me anything you think might help me.

Context :
I am doing a VR project in which I use a [KinematicBody] moving toward the [ARVRController] for each hands, this allows me to have hands interracting with the physic of the scene.


##problematic##
I want to be able to trigger a function with the object that collide with my Kinematic body as an input when colliding.


#My approach#
to access the collider, I use the collision property of the [KinematicCollision]
in the script of my hand, I have that (where movement transform is a valid [Vector3]):

KinematicCollision collision = MoveAndCollide(movementTransform);
//when a collision occurs
if (collision != null) {
    GD.print(collision.Collider.name)
}

#issue#
The KinematicBody.Collider property is of type [Object] and the .name property is part of the [Node] type, so the compiler tell me something like this:

'object' doesn't contain definition for 'name'

##My guess##
There is probably a way to tell the compiler that the [Object] outputted by collision.Collider inherit [Node] but I can’t find the way to do so, please tell me if I am missing something or if I’m wrong.

I found out about casts; but still don’t really know how it works,

For anyone wandering the same thing (“convert” the [Object] to a [Node] or any other class) you can use the following syntax:

((Node) collision.Collider).name

with Node as the target class, collision.collider as the [Object] and name as the target property

MajorBarnulf | 2020-09-05 23:34