1
$\begingroup$

I've encountered this problem a few times from workaround, but it keeps coming back. I have no idea how I solved it initially, but now the problem has persisted for quite some time.

What I want to do:

Is to have my player and weapons all in one .blend, and to let the player switch out weapons, whereby a given weapon is added or deleted whenever a weapon change occurs.

Problem:

This is requiring the weapons to be in a separate layer. Linking object doesn't seem to support this. I've tried using different groups for each set of assets, but that also did not appear to do anything.

Picture related, the groups I am referring to in game. Any help is greatly appreciated. I can provide additional information if necessary.

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

Be aware the BGE does not know about layers (in terms of logic and object management). The differs between

  • active objects (residing in visible layers inside Blender) and
  • inactive objects (residing in hidden layers inside Blender).

This assignment is fixed. You can't change it while running the game.

Finally you do not need to do that.

The trick is to place the linked objects inside the hidden layer. This makes them inactive and therefore available for AddObject.

I usually assign linked objects (even single objects) to a group. I link the group from the target blend file.

This allows me to instantiate the group as often as I like in any scene and any layer.

In your case you can create an instance in an hidden layer. While you run your game you can addObject() all objects of the instance.

$\endgroup$
2
  • $\begingroup$ For some reason that wasn't working for me, even with hidden layers. I will probably encounter it again, so I will go through your answer then. For now I fixed the issue I was having by using addObject(), but I had to separate the player group and the weapons & ammo group. In my case, this also made it easier to manage each object and file. $\endgroup$
    – Zenet
    Commented Aug 28, 2017 at 17:55
  • $\begingroup$ Separating them is always a good idea. You can indeed assign objects to different groups. You can even have nested groups (by assigning a group instance to another group). But not all combinations do work within the BGE or work as expected. $\endgroup$
    – Monster
    Commented Aug 29, 2017 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .