Player Putting On Clothes in BGE

So I’m guessing there’s a “getMesh” type of function in Python available? I think that would kind of justify it.

Guys, I found a simple solution that doesn’t consume too much time to set up. It’s as simple as setting up a string property, with the string being the name of the mesh property.


import bge
from bge import render, logic
render.showMouse(1)


scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner


mouseOver = cont.sensors["mouseOver"]
click = cont.sensors["Click"]


if click.positive:
    if mouseOver.positive:
        target = mouseOver.hitObject.getPropertyNames()
        if 'Cloth' in target:
            own.replaceMesh(str(property?))

Now, there’s a slight problem. I have not idea what to set for “property?”, as you can see the question mark I set there.

The value of the string is assigned there, to replace the mesh with a mesh with a similar name.


from bge import render, logic
render.showMouse(1)


scene = logic.getCurrentScene()
cont = logic.getCurrentController()
own = cont.owner


mouseOver = cont.sensors["mouseOver"]
click = cont.sensors["Click"]



if click.positive and mouseOver.positive:
    target = mouseOver.hitObject
        
    if 'Cloth' in target:        
        property = target['Cloth'] #change this(Cloth) to the property name that is holding the new mesh
        own.replaceMesh(property)

Removed BGE, you importing the modules already, look at what i have changed in the first few lines.
put the click and mouseover on 1 line, one check is better then 2.
to read a property its own[‘property_name’], so i changed your target line as well.

have fun with it.

Yeah, I could do that. The problem is: That it’s going to consume a lot of space since there’s going to be a lot of items.

So I figured that instead of listing every item for every property, it could be as simple as using the mesh’s name for the string value. Then the own.replaceMesh() would just use that string value from the property “Cloth”.

Edit: You can disregard that. I just forgot to remove the “bge” from certain segments. Thank you, this is going to help me in the long run.

I won’t forget to mention you guys at the end of my credits.

why? you got 1000 objects with the same property, script grabs that property from any object you click on, then it set that property as the new mesh. the only thing you need to do is changing the value of the cloth property for the mesh you want to use.

so obj1 has cloth -> blue pants
obj2 has cloth -> yellow pants

you got 2 meshes 1 called blue pants and 1 called yellow pants
script grabs the property cloth, put that cloth value into replaceMesh and own will change it mesh.

this is the correct way to do it.

#edit
this comment


property = target['Cloth'] #change this(Cloth) to the property name that is holding the new mesh

is meant for you to put in the correct property name you are using, you check the object for a property called Cloth, so i guessed Cloth has the mesh name, so i added the comment to tell you to set it to the right one in case that Cloth is not the property that holds the mesh name, you never have to change a single character in the script.

Yeah, thanks. I made an edit, not sure if you saw it?

Haha, well either way. It works. I’ll post a blend right about now…

ClothingCollectingExpierment.blend (571 KB)

This is for your guy’s efforts.

Alright, I’m not too sure whether BA artist can still see this?

So I tried to make a cloth exchange system, where you pick up a piece of cloth. Then when you pick up another piece of clothing, you drop the current clothing and receive the new one with the original property. Now my problem is that it drops the cloth with the correct property and mesh, but when I collect another one; the property resets and the mesh turns into a plane for some reason.

Here’s the blend file:ClothingCollectingExpierment.blend (589 KB)