Game Engine / Python Initialisation and Linking

Hi,

I think I’ve come pretty far, but whats going on here I can’t figure out by my own:

I’m using multiple blend files for enemies and stuff which I link into the main level blend file via groups.

As I understand it blender creates empties and uses dupli groups to “link” to the one in the other blend file.
So there are multiple named empties “Enemy.001”, “Enemy.002” and so on and one invisible linked original “Enemy”.

But what happens exactly on game engine initilisation? Are the emties replaced by newly created duplicates
of “Enemy”? Or are they still there? (At least I can access them via ‘groupObject’) On what does the python code operate when I write “cont.owner.xyz()”? What do I get if I access scene[‘Enemy.001’]? Is there any documantation on this? Or tools which I can use to get better insight?

I’m constantly stumbling on stuff which isn’t working as I would expect it but although on stuff which works which I wouldn’t expect to. So knowing how this is internally done would help me a lot to continue from there on.

Thanks a lot!

Scheintod

Instantiating acts the same way as AddObject. The group objects are added while inheriting the transformation from the instantiating object. The group object will preserve their relative relationship to the group center.

No they do not replace the instantiating object. Beside the python properties there is no further relationship between instantiating object and instance members.

depends on what cont contains ;).

I guess you mean the current controller (SCA_IController). Obviously SCA_IController.owner is the game object that owns the controller.

This is invalid code. There is no index on scene.

I think you mean KX_Scene.objects[ key ] where key is an object name.
You can get both, the instantiating object or any instantiated object. Be aware names are not unique. This search method gives you ANY object with the given name, without any error or warning. So I recommend to avoid it. Better search through all objects looking for multiple objects with the same name.

BGE API

I do not think so. But you can use the Analyzer to inspect your scene.

Hi,

thanks for the quick answer. It helps a lot.

So after linking - lets say 100 - instances of “Brick” (it’s a Jump’n’Run) I finally end up with 200 objects: 100 Empties named “Brick.001…100” and 100 copies all named “Brick” all with their own controllers and so on? But this explains why parenting did never worked the way I expected it to.
So in my game initalization I could delete all these groupObjects and free some resources?

Ok. That names aren’t unique is valuable info, too. Indeed I didn’t expext this. So I assume they aren’t stored in a map (like I expected) but a list with some fancy accessor method.

Yeah. Been there a lot but didn’t find anything regarding initialisation. Am I holding it wrong?

Thanks. This is a nice starting point and I can extend it to show me more stuff I’m interessted in.

One additional question: using ‘groupObject’ I can get from a linked object to it’s instantiating object. Is there the other way, too?

Thanks again

Scheintod

Yes, you get 200 objects (if the group consists of a single object).
Yes, you can delete any object you want. Be aware if it is a parent its children will be deleted too.

Exactly, it is a list with all active objects. You can loop through it to get all objects.

Yes, you can. Look at the BGE API. The according attribute is documented next to groupObject. I do not have it here. I cant tell from my memory. Be aware it is a 1:n relationship.

Hi Monster.

OK. Just to be complete:

The reverse of ‘groupObject’ is ‘groupMembers’.

There seems to be at least one additional implicit connection between an object and its ‘groupObject’.
If you use the ‘groupObject’ in newObj = scene.addObject( ‘GroupObjectName’, someobject ) this will not only create a new empty but although its ‘groupMembers’. This can be a little irritating if you try to animate the ‘newObj’. (I guess this is what I mean that some things work which i expect not to but others don’t which I expect to work…)

Regards & thanks again.

PS:
I just found your guide to linking Libraries. Perhaps you could update it to reflect this stuff. Currently it says: “Pivot objects do not know the instance objects they added”

Another short note:

‘.groupObject’ and ‘.groupMembers’ don’t work on objects on inactive layers. But accessing them via name does work. This has puzzled me in my test-script for this…

You do not create new instances by “addObject” with the group name. You addObject an instance from the inactive layer (you accidentally got the same name :wink: ).

E.g.
Group: “Group” with group member “Cube”

Instance (inactive): “Group.instance” (with instantiating object [Empty] + instantiated objects[Cube])

AddObject: “Group.instance” (with instantiating object [Empty] + instantiated objects[Cube])

As an instance consists of the instantiating object + instance members you get all of them.

You are right this is not true anymore.