0
$\begingroup$

Let's say I have a *.blend containing a few objects which I would like to add to a group and use as a template. This could be some (textured) meshes and a text object which are connected in a group. A totally arbitrary example might be a player mesh (e.g. a tank) with a health bar and a life-counter.

Then, in another blend, I linked the above group, added them to an invisible layer and and would like to:

  1. Add instances of the whole group, staying connected as known from the editor
  2. Change properties of the group members (e.g. text)
  3. Move the whole group at once with Python

How can I achieve that?

PS: I'm using about the standard BGE (2.79), not the UPBGE fork.

$\endgroup$
0
$\begingroup$

I suggest to link groups (rather objects).

  1. Open your target blend file
  2. Link (not append) the group(s) from the asset blend file
  3. Create an instance of the linked group at an hidden layer (an instance is an empty with dupli group enabled).
  4. Use the instance as base object when creating new object in-game (via AddObjectActuator or via Python).

Remarks: The copied object is still an instance and consists of empty + group objects! As usual the empty has no relationship to the group objects. Moving it after creation has no effect on the group objects.

$\endgroup$
  • $\begingroup$ Thanks, Monster! The steps you describe are exactly what I did to link the templates. And your last remark "Moving it after creation..." is right - I observed this myself once and fount it very counterintuitive. This behavior is not obvious in my example, since all transformations are driven by the physics engine. However, in case the linked group has one "root" parent object, one can move this instead. $\endgroup$ – AeroLynx Mar 9 '18 at 14:15
  • $\begingroup$ This is the major difference between Blender and the BGE. With a little Python code you can parent the group objects to the empty or the empty to a group object. The BGE does not know which direction you need. I guess this is the reason why it has no such relationship by default. $\endgroup$ – Monster Mar 12 '18 at 13:19
  • $\begingroup$ Actually, I found this behavior very annoying. From the editor, I was used to move a linked object around with the mouse as one connected piece as usual. It "lives" in the hierarchy like normal objects do, so I would expect, that it can be moved around with a motion sensor or with *.worldPosition like his brothers and sisters. However, it does not work like that. And since it doesn't, you end up with two options: Asking Google/Blenderartists/here or trial and error...which may heavily discourage new users. $\endgroup$ – AeroLynx Mar 16 '18 at 8:33
0
$\begingroup$

Here are two example files achieving this:

template.blend

This contains two template groups named template_A and template_B, each consisting of two meshes (Suzanne and Cylinder) and a text object, but different hierarchy. See images enter image description here enter image description here - In the group "template_A", Text and Suzanne are parented to the cylinder ("root" parent). - In the group "template_B", there are no parent-child relations.

addTemplate.blend

enter image description here in this file, both templates are linked and placed on layer 2. A cone object acts as spawner,moves around and reacts on Keys A ("template_A") and B ("template_B"). The script add handles the reactions and sets the string (Question 2).

Note that when template_B is added, the three objects fall apart (they have different translational damping), while in template_A they stay connected (question 1).

Edit: As Monster pointed out in the comment, you can not move the whole group at once by changing e.g. world.objects["template_A"].worldPosition. Instead - you need to move the "Root" parent (see image above), which can be accessd by e.g. world.objects["template_A"].groupmembers["Cylinder"]. This is related to the additionally added question 3.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.