Delete children

Is there a script to delete all children of an object?

Need this fast…thanks :slight_smile:

import bge

cont=bge.logic.getCurrentController()

own=cont.owner()

if object.children!=None:
for objects in children:
objects.endObject()

import bge


cont=bge.logic.getCurrentController()


own=cont.owner


if own.children!=None:
    for objects in own.children:
        objects.endObject()

Ok, but why doe this happen? (press play and press 1,2,3 multiple times)
the guns glitch up…I checked everything and don’t know what’s wrong
I’ll attach a google drive one
https://drive.google.com/file/d/0B4Q6-P5KwZ2QSU5QdU12NlNqaTg/edit?usp=sharing

Ok, I see this setup and it’s a little hard to handle

I will try and cook you up something less “divided” as it’s hard to tell what is going on.

ok check this out,

this does the exact same thing, but the gun is self contained.

mind you you will have to setup each gun, but it should make it much easier

Attachments

WeaponSelfContained.blend (460 KB)

I am going to build the full system, as I need the same thing for wrectified,

here is a updated version (all I am doing for tonight)

this manages reloading (R key)

the player can activate firing, but firing is in the gun

the player activates reloading but reloading is in the gun

the player gun swichty system removes the ammo, and adds it to stock, then ends the gun

Attachments

WeaponSelfContainedV2.blend (494 KB)

@BluePrintRandom, there is an EDIT button. We told you multiple times to use it. It is left of the reply button. Even a child is able to find it.

Your subsequent posts are flooding the forum.

It does get a little obnoxious, so I agree with Monster. Still looks good though, BPR. But I bet my dog could find the edit button.

IIRC, you also told him that “objects” is not a proper name when referencing a single object, among other things.

In reading (or trying to read) a number of his posts, I am now convinced that he suffers from a learning disability of some sort. I feel sorry for him, but I don’t think he should be allowed to spam threads, and the forum in general.

PS:

The function that should actually end all children (his code doesn’t deal with children’s children):


def end_children(parent):
    for c in parent.children:
        end_children(c)
        c.endObject()

isn’t that what I’ve already done?
the eyes trigger the gun controller to add the gun, and shooting and reload are in the gun. I just haven’t made reload yet though.
I’ll post a more complete version of what I’ve done…

Oh and there’s an annoying upload problem I’m having…My game is 5MB compressed so every time I want to upload the problem, I have to delete most of the objects, textures and materials to do so…any ideas on how to eliminate this problem?

Mediafire. Or Google Drive. Or Dropbox. Or other.

Off topic:
While I do agree that reading multiple tiny posts can be a hassle, I don’t mind it. I think he’s just using it like a chat
Some posts, like #7 are meant to be just a single post. I kind of don’t like reading one giant post that might take up the whole page

On topic:

The function that should actually end all children (his code doesn’t deal with children’s children):

Doesn’t that already happen automatically? all children are input into the scene if the parent is and deleted when the parent is deleted right?

I would connect this post and the previous one I made, but there’s no “connect” button or something. Just a suggestion…can you guys put one in there? I think it would benefit more people than just me

Oh, yes, of course (my head was stuck in a different engine).

Still, I would recommend you use this code, instead of his:


def end_children(parent):
    for c in parent.children:
        c.endObject()

It’s better, due to proper naming, and no redundant checks.

I don’t feel sorry for me, where are your games btw?

back to ON Topic.

this is far less complicated.

his whole system is a mess of states,

this is not.

Attachments

WeaponSelfContainedLogicV4.blend (497 KB)

Point of information, objects do also have a childrenRecursive attribute, though I suspect you’ve already considered this case, given that ending objects linearly will likely cause reference errors when an object is ended before its children (as you iterate through, unless the attribute traverses bottom up)

Jeez, a little extreme, don’t ya think? All the blatant name callings, and insults…
Sure, he posts a lot (I never noticed until now, tbh) but he’s incredibly helpful.

OT: I have nothing to contribute to this thread, so I’ll be on my way

I would only parent one item to the gun manager ever,

and that way if there is a gun, its own.children[0]

(check my solution)

it uses .02ms->.04ms peak logic

btw you can use the property “Fire” to handle animations fire and reload,

and “Init” can handle “drawing” animation

I’ll need to rethink “gun remove” as it is instant at the moment.

*** Moderation ***

Your complete game is not needed as long as your complete game is not the problem.
I strongly suggest you recreate your problem in a small demonstration .blend.

The benefits:

  • In a lot of cases you will discover the solution by yourself, when doing that.
  • The file is small.
  • The file focuses on the issue.
  • The file is much easier to read without distracting the reader with unrelated information.
  • You do not need to post your resources.
  • You learn to structure your game in a modular way.
  • You help BA to save storage space.

Drawback:

  • More work for your… but you want us to help you :wink:

Unfortunately this is not a chat and we do not want to be one. BluePrintRandom has to follow the forum rules as everybody else here. One rule says: “Don’t flood the forums with … unnecessary posts …”

He knows the solution: edit button

You can edit even your older posts. But if there are other posts already it is better to post a new one, except you want to correct the information of the old post. If you add information I recommend to mark it somehow that a reader knows it was added later.

*** End of Moderation ***

To provide some help on topic (not moderating):

It took me a while to identify the object that execute the deleteChildren.py code. An demonstration .blend as mentioned above would surely be an help. I do not even know how to test this game.

You mention you loop backwards through the code to avoid issues on deleting. This is not the case in this situation as you do not remove elements from the list. You end game objects. This has no influence on the list. The list will stay the same so you are save to loop forward.

Anyway the mentioned code from BluePrintRandom is sufficient (but a little bit too much).


def endChildren(object):
    for child in object.children:
        child.endObject()

Attribute children always returns a list. If there is no child the list is empty. You can test this situation.

You can but you do not need to end the “children of the children”. As you already expect the BGE ends objects together with their children. You can test that either.

Do you still have problems?