Replace mesh with ray object

Hello there, im wondering if its possible to replace the mesh of an object with the mesh of a hitObect.

Or possible to do something similar to this, where whatever object the ray is over in the players hotbar, an empty object in the players hand will copy its mesh or something rather.

def Hand():    
    cont = bge.logic.getCurrentController()
    own = cont.owner
    scene = bge.logic.getCurrentScene()
    ray = scene.objects['selector'].sensors['Ray']
    hand = scene.objects['Hand']
    
    if ray.status == bge.logic.KX_INPUT_ACTIVE:
        hand.replaceMesh(ray.hitObject)

My attempt, but replaceMesh needs a mesh name and wont accept ray.hitObject

ray.hitObject.name

Also in your case since you’re already using Python you may want to use obj.rayCast() or obj.rayCastTo()

EDIT: I think thet replaceMesh uses a mesh, not an object name, ray.hitObject.meshes[0]
And you probably want to check if it’s none before: if ray.hitObject != None: hand.replaceMesh(ray.hitObject.meshes[0])

still getting errors, wonder if there is a way to call hitObject.Mesh or something like that, googling it now. Cheers!

Thank you sir!

Objects have a list of meshes, use the first one. hitObject.meshes[0]

Sent from my LG-H440n using Tapatalk