Is there a way how to change created object in-game into a single user / independent object?

When I create an object in-game it acts as a copy through Alt + D and when I move the object’s texture, I move the texture of all copies of the objects created in-game.
I was wondering if there is a way like in Blender when you press U, you can change the object into a single user.
There is also this python script shown:

bpy.ops.object.make_single_user(object=True, ...)

Is there a way how to change that in-game created object into a single user object?

Short answer is no.
Long answer is yes…ish.

You can use logic.LibNew() to make an almost unique object(makes a new library from existing data). I say almost because in most ways it will be a completely unique object with it’s own ID and it’s own mesh. But the problem is if you make more than one copy of these, the meshes will all have the same name. They’re still otherwise unique so you can do UV animation on them and they will all act separately as you would expect. This causes a problem when you need to free the library as it gets a little screwey.

For a simple function that acts similar to scene.addObject(), you could do:

def addObjectUnique(obj, ref): # obj is object to copy, ref could be the object calling this function

    # You want the name of the mesh to be copied
    mesh_name = ref.scene.objectsInactive[obj.name].meshes[0].name
    
    # This is a way to make a unique name for the new library
    lib_name = "NewLib_" + str(logic.getRealTime())
    
    # This creates the new library itself. You can make libraries with 
    # more than a single mesh but just one works for this function.
    new_lib = logic.LibNew(lib_name, "Mesh", [mesh_name]) 
    
    # Now add the object like you would normally
    new_object = ref.scene.addObject(obj.name, ref, 0)
    
    # Replace it's mesh with our newly created mesh from the new library(it's mesh zero)
    new_object.replaceMesh(new_mesh[0].name,True,True)
    
    # Return our new object
    return new_object

Use it like you would use addObject() for example:

new_thingy = addObjectUnique(owner.scene.objectsInactive['Some Object'], owner)

You’ll get increased memory usage the more libraries you create if you’re not freeing them with logic.LibFree() when you’re done with them. I usually try to avoid messing with the logic.Lib* functions myself.

1 Like