Remove/reset compound collision shape?

That only works with separate root empties - If you’re using instances of the same one, each one spawned inherits the collision shape of the previous.

At least, that’s what I think is happening. This parenting system all behaves so weirdly, it’s hard to understand what’s affecting what.

Just tested, and apparently you don’t even have to delete the parent - All instances spawned will copy the hitbox of their duplicate. If there’s multiple instances already, the new one will combine all the other hitboxes to form its own.

Yeah if you unparent all children,
Spawn the new instance,
Reparent all children it works fine.

But new instance still has the old one’s collision geometry…

Do you have a “empty” compound core
Object you initially spawn?

I have done this before,
You just parent all objects to the core on frame 1.

Yes, it’s an empty with ‘compound’ checked, and all objects are parented to it. But when you try to replace it, the new one has the exact same ‘invisible cubes’ attached to it.

Yeah,

ChildList =  [] 
for object in own.scene.objects:
    if object.name =="Object Name":
        ML = [ object, [  ] ] 
        for child in object.children:
            ML[1].append(child)
            child.removeParent()
        ChildList. append(ML) 
    
Added = own.scene.addObject("Object Name", own, 0)
Added.worldPosition = someWorldVector
for objectList in ChildList:
    For object in objectList[1]:
        object.setParent(objectList[0],1,0) 

I am on a phone so I can’t share a blend (power is out =|)

1 Like

@BluePrintRandom
I still can’t get it to work - Though I’m not entirely sure why or what’s wrong. All I can manage at this point is random ‘ghost’ cubes popping up and the occasional Blender crash. The only thing I do know is that new instanced objects sometimes spawn with the collision bounds of the object spawned before them.

It’s a confusing mess, but I think loading objects from a file could be a workaround. The only problem is that apparently, you can only have one loaded at a time…
Any ideas?

you tried my code?
because I have done exactly what you are trying to do…

“object name” needs to be replaced with the name of your object to spawn.

For the record, I was able to load multiple from the same file; never had a problem with being limited to one instance at a time.

1 Like

but the copies loaded are the same ‘lib’ so the collision shape is shared @Attackapaca

… No, they aren’t. By LibLoading the separate scene each time you need a fresh compound mesh, you’re creating distinct instances. I’ve managed to dig up my old demo files; they’re attached. Hit [space] and it’ll spawn a new compound mesh with some cubes randomly distributed along one axis; you can see (with the physics visualization on) that they have distinct contacts. Hit [backspace] to LibFree() all instances (which consequently deletes them and their children). This method seems to show no performance impact beyond what you’d expect from spawning a new physics object (much to my surprise).
LibLoadTest.zip (328.0 KB)

1 Like

Nice!

I never had to go that far, I just unparented / reparented everything.

maybe it was ‘libNew’ I tried a very long time ago

¯_(ツ)_/¯ Whatever works!

I see where I went wrong. In the line that goes, bge.logic.LibLoad(name, 'Scene', lib_data) , I put the filepath in the first variable instead of the object name (which must be changed for each spawn). Changed that, and it works completely fine now :smiley:

I got the code to work as well! While I figure it’d be less CPU-intensive to just avoid the problem entirely, it’s nice to know there’s more than one way to do it.

The only thing left to solve now is that children can’t be detected by sensors; but that’s a problem for another day.

Thanks guys!

2 Likes