0
$\begingroup$

I am working on a game in the blender game engine. I need to Position an empty, spawn an object at it, re-position it, and spawn another object. When I run my script it only appears to have activated once. I have recreated the scenario in another.blend file and the situation still persists.

Here is my code:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner


actu = cont.actuators['SpawnCube']
own.worldPosition = [4,0,0]
cont.activate(actu)
own.worldPosition = [-4,0,0]
cont.activate(actu)

Running in the embedded player

$\endgroup$

2 Answers 2

0
$\begingroup$

yeah that is an issue when using Logic Nodes. I think some of them can only be activated once per frame. There is however a solution to your problem and its this:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()

own.worldPosition = [4,0,0]
scene.addObject('NameOfTheObjectToAdd', own)
own.worldPosition = [-4,0,0]
scene.addObject('NameOfTheObjectToAdd', own)
$\endgroup$
1
  • $\begingroup$ Thank you so much! I will have to give this a shot after work. $\endgroup$ Jul 2, 2017 at 13:45
0
$\begingroup$

An actuator can be activated as much as you want.

Be aware it will run ONCE per frame when it was activated.

What you want is different. You want to manipulate the scene at the moment of executing the custom controller's code multiple times. Josip's Answer should be sufficient enough.

alternatively you can use the AddObject actuator (for setup the master object via GUI):

addObjectActuator = ...
addObjectActuator.instantAddObject()
addedObject = addObjectActuator.objectLastCreated # call that after instantAddObject() only

See BGE API

$\endgroup$

You must log in to answer this question.

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