How to properly add group to a group?

Hello.

  • I have a plane. It is a group consist of wings, cockpit, customized sensors, etc.
  • I have missiles - A group consist of customized sensors, fins, etc.
  • I wan’t to arm my plane with those missiles.
  • The problem is when the plane moving, the missile left behind.
  • How to properly add group to a group?
  • I might have many other planes (group) too.

Thanks

you need to parent it to the plane, or copy to location/rotation of the plane.

those missles are static? or do you spawn them?
Because i would parent an empty to the plane, parent missles to the empty, move em to layer 2 and spawn in the empty.

so you spawn everything and due to the empty is parented to the plane it will stick.

Scene:

  • F15 (group)
    - Component: Variant Single/Double seater, side fuel tank, gears, etc.
  • Missiles
    - AIM9(group), AIM7(group), etc
  • Explosions
  • Other Assests
  • Theater_Iraq
  • Theater_Kuwait
  • Theater_Afghanistan

Currently, the background smokes (from other scene) are manually placed.
The fuel tank (object) is parented to the empty under the belly.
The missile (grouped: fins, sensors, etc) are manually place and parented to the plane in F-15 scene.
Spawning missile from another scene or the same scene (different layer) as in F-15 only shown in the F-15 scene.
F-15 (group) are placed manually at the theater (in the video/game scene)

Attachments

badParentingSkill.blend (105 KB)

/uploads/default/original/4X/8/2/5/8250071d57066db91425eda5bcbab8ff57c85ad0.pngstc=1

this_ParentingSkill.blend (106 KB)

this what you mean?
it trows an cycle dependency error, so i think there is a better way for it, but i have no idea, anyway it works.

Attachments


not accurately what you want only a tip/trick

for in game you can use empties and parent them to the place where the missiles should be and than you can with python or game actuators parent the missiles to the empties. (so if you want that they fall down if they don’t parented anymore)

did you try to make something with duplication group and bound the main object to the plane or else?
don’t know if this work

did you try to make something with duplication group and bound the main object to the plane or else?
don’t know if this work

look at the blend, he uses 3 scenes, 1 group a scene, and he shows them all in scene one.
the error is due to the parenting, because you parent an object to an object that is in an other scene.

I guess, I will try to do all the parenting/missiles attachment through Python - starting from a root (single empty) from theater.
Thanks guys.

Thanks monster. Its a nice reference. I’m going for python.

Currently I’m cleaning up the Asset files. Just found out that using groups a lot may generate tonnes off orphan data.

Using libload,
I will load the scene + content, parent it, hide it.
…then I will try to instance the Asset or another plane. Eg: wingmen, NPC.

Tips and guidance are welcome and very very much appreciated.

addedInstance = own.scene.addObject('instanceCopyNameOnHiddenLayer')
for objects in addedInstance.groupMembers:
    if 'PropertyTag' in objects:
        do.stuff()

https://www.blender.org/api/blender_python_api_2_77_0/bge.types.KX_GameObject.html?highlight=groupmembers#bge.types.KX_GameObject.groupMembers

Thanks BluePrintRandom. I’ll test it out.

I would not do it that way.

The reason is simple, you need to know the internal structure of the group.
This may sound like it is no issue.

Imagine you change the group. Do to this dependency the above code might not work correctly anymore. This issue might be less obvious and more dangerous, when the group resides within another file. The group and the users are explicitly separated. When you maintain your asset files you will surely not see this kind of dependency -> high risk on introducing errors.

I suggest to design your assets in following way:

A) only the group knows about the structure of the group (no body outside the group)
B) define an interface how to interact with the group without publishing internals

For example you want to create a flag with pole and softbody plane. The softbody gets constraints to the the pole. The whole flag (group) is supposed to follow wherever the pole gets parented to.

How to do that:
Search the pole, and parent it to the target
Who searches?
What is the target?

Searching the pole from outside needs to publish internals (how to find a pole). But the outside knows the target. But it is still no good design. Image you later want a base where the pole is parented to. That means you need the change all users of the group.

Let the group do that:
No need to search, the group already knows the pole (or whatever the base is).
The group does not know the target … you need an interface to tell the instance what the target is.

This example is pretty simple: you can use the instance object as target. Blender allows you to parent the instance object to the real target (e.g. a car).

Solution:

  • interface: parent is the instance object
  • implementation: one object of the group parents the pole to the instance object
  • upgrade: the base will be parented to the instance object. As the interface does not change the users do not need to change.

Be aware:

  • a group has no instance object. You need to test this behavior on an instance rather than the group (= instantiate the group in your test scene.)
  • changes to the interface require a change to the group and the instance users.
  • instances can be part of another group

Examples of other interfaces:
Properties:

  • use the properties of the instance object for input/output of properties

Other objects:

  • you can parent other objects to the instance object. You can differentiate them by properties.
    example: you have a vehicle as car, you want to parent something the body of the car (e.g. a flag).

  • you can use actuators that refer to specific objects at the instance object
    example: Use the camera actuator to refer to the camera, the instance can read the reference from the actuator (without activating it). It is a bit thinking-around-the-corner, but you do not need to establish a parent-child relationship.

  • you define criteria on how to identify objects within the current scene.
    Example: A car should steer on a navigation mesh. This solution requires the criteria uniquely identify objects. E.g. two navigation meshes would cause trouble.


I’m sure there are many more options.

I hope it helps you a bit.

I would not do it that way.

The reason is simple, you need to know the internal structure of the group.
This may sound like it is no issue. But it is.

Imagine you change the group. Due to this dependency the above code might not work correctly anymore. This issue can be less obvious and is more dangerous when the group resides within another file. The group and the users are explicitly separated. When you maintain your asset files you will surely not see this kind of dependency -> high risk on introducing errors.

I suggest to design your assets in following way:

A) only the group knows about the structure of the group (no body outside the group)
B) define an interface how to interact with the group without publishing internals

For example you want to create a flag with pole and softbody plane. The softbody gets constraints to the the pole. The whole flag (group) is supposed to follow wherever the pole gets parented to.

How to do that:
Search the pole, and parent it to the target
Who searches?
What is the target?

Searching the pole from outside needs to publish internals (how to find a pole). But the outside knows the target. But it is still no good design. Image you later want a base where the pole is parented to. That means you need the change all users of the group.

Let the group do that:
No need to search, the group already knows the pole (or whatever the base is).
The group does not know the target … you need an interface to tell the instance what the target is.

This example is pretty simple: you can use the instance object as target. Blender allows you to parent the instance object to the real target (e.g. a car).

Solution:

  • interface: parent is the instance object
  • implementation: one object of the group parents the pole to the instance object
  • upgrade: the base will be parented to the instance object. As the interface does not change the users do not need to change.

Be aware:

  • a group has no instance object. You need to test this behavior on an instance rather than the group (= instantiate the group in your test scene.)
  • changes to the interface require a change to the group and the instance users.
  • instances can be part of another group

Examples of other interfaces:
Properties:

  • use the properties of the instance object for input/output of properties

Other objects:

  • you can parent other objects to the instance object. You can differentiate them by properties.
    example: you have a vehicle as car, you want to parent something the body of the car (e.g. a flag).

  • you can use actuators that refer to specific objects at the instance object
    example: Use the camera actuator to refer to the camera, the instance can read the reference from the actuator (without activating it). It is a bit thinking-around-the-corner, but you do not need to establish a parent-child relationship.

  • you define criteria on how to identify objects within the current scene.
    Example: A car should steer on a navigation mesh. This solution requires the criteria uniquely identify objects. E.g. two navigation meshes would cause trouble.


I’m sure there are many more options.

I hope it helps you a bit.

Group instances (and python components) are my bread and butter. It sucks that you can’t parent groups in the editor.

I use a Monster-flavored version of what BPR does.

if owner.groupObject is not None:
    # This object is part of a group
    parent = owner.groupObject.parent
    if parent is not None:
        # Use the same parent
        owner.setParent(parent)

Thanks for your valuable input guys.
I’m having weird huge > 50% GPU Latency when using libload.


import bge


path = bge.logic.expandPath('//')


def addF15(con):
    lgc = bge.logic
    sce = lgc.getCurrentScene()
    own = con.owner
    
    #Stop double execution
    if con.sensors[0].positive != True:
        return


    #lgc.LibLoad(path+'mzAssetF15.blend','Scene')
    lgc.LibLoad(path+'debugGPULatencyObj.blend','Scene')
        
    #mzNewObj = sce.addObject('F15')
    mzNewObj = sce.addObject('Cube')
    #for o in mzNewObj.groupMembers:
    #    if not o.parent:
    #        o.localPosition = own.localPosition
    #        o.setParent(own)

debugGPULatency.zip (162 KB)