Edit actuator - Add object .. okey ... but

(blenderaptor) #1

I presume it’s to create many instances from a same object … but… then ? How can i possibly make a difference among them ? An hidden ID for each ? How select them with Python ? If the added objects are bullets of a gun, i understand . But what if , for exemple, i want to add the same NPC at many empty location. To make them different, i can use different mesh models . Ok . But 1 instance lose 5 hp points. Will it affects the others ? Can i instant rename them when created ?

(blenderaptor) #2

ok, not possible to rename them but attribute an unique Propriety value after creation

# Note: This example assumes that you have a basic understanding of Python.
# Also, it assumes that your add object acuator is defined as the variable act.
act.objectLastCreated['Prop'] = 1 #Or what ever you want.

but after the author says

Well the problem was that I was referring to 
my enemies with GameLogic.getCurrentScene().objects[“name”]
and not own.name

i dont understand . Can someone explains me ? The ‘own’ refers to the empty that spawned the instance ? So i presume he made a python for each of his empties . But he was wondering how he can measure the distance between his character and those new instances , but then he came with " own.name " (refering to his empties) … but then he’s not measuring the right thing as the instances dont necesseraly stay still on those spawner empties… I will check …

(blenderaptor) #3

ok, the answer is here

(- Click for resources) #4
def add_object(cont):
    own = cont.owner
    added = own.scene.addObject('Cube', None, 0)
    added.worldPosition = [0,0,5]

As you can see you put the addObject into an variable, then you can change anything you like.
Name can’t be changed however i read somewhere that you can change the name in UPBGE.

(blenderaptor) #5

yep, that is what has been found on the other thread. But i guess that the new “added” cannot be used with any actuators. For exemple, if “Cube” is on a motion actuator all the “added” will move together

(jesusmora) #6

i use property ids. you can do:

scene = bge.logic.getCurrentScene()
for abc in range(10):
     ob1 = scene.addObject() #etc 
     ob1["id"] = abc

in upbge you can rename objects with obj.name = "name"

(- Click for resources) #7

def add_object(cont):
    own = cont.owner
    added = own.scene.addObject('Cube', None, 0)
    if not 'added_list' in own:
        own['added_list'] = []
def move_all(cont):
    own = cont.owner
    if 'added_list' in own:
        for obj in own['added_list']:
            obj.localLinearVelocity = [0,1.4,0]

(blenderaptor) #8

i meant : not possible to make 1 instance benefit alone a specific actuator.

For exemple, i have an armature object “bad_npc” , i make 3 instances of this object. I cannot make 1 of them animated walk and the 2 others idling or motion moving

(blenderaptor) #9

Why i want to know all this :

I want for exemple 5-10 ennemies on the same scene. Ok, lets say that i have 10 different objects (i let away the idea of having 10 instances of same object) ; my problem is that i dont want to make 10 times all the logic brick . Those 10 “different” ennmies share exactely the same behaviour. What can i do to make stay with 1 logic brick system for all the NPC ?

(blenderaptor) #10


i just discovered the python API modules for BGE so i can get rid of the brick actuators. For exemple , replace an action actuator with python is :


cool. Im very new with BGE, learning lot, but i really believe that for a newbie like me
is just un-readable. In a way one have no idea about class, modules, libraries, types, notations, etc etc … bge.logic , bge.type … bla bla bla … and so on … need just exemples to understand … oh no wait … that would be too easy and theorically permissive !

(- Click for resources) #11

No because you can’t create an actuator, so we can’t give 1 ‘copy’ of a object specific details/actions.
That’s why every one says, if you really want to make a game start learning python.

With python it’s all possible, due to the fact that you can store the object and acces them anywhere.
thus we can give each ‘copy’ his own behavior, and with python you can even change the bricks settings.

for python in the game engine, the logic section is what you want to look at first, everything else is for a later time (when you actually need it). https://docs.blender.org/api/current/bge.logic.html

So dive into the forums resource section, a lot of resources/examples of things there.

if you are eager to learn then go for python, you can learn how to code just by watching youtube tutorials, and within a week you build your own stuff.

You can however combine the two. let bricks run on properties, and change the properties per object.
or use states, different states for different copies, when you add a copy you set the right state, etc.

(blenderaptor) #12

hey, thx for the answer and also the answer on the other post.

I dont know if you notice, but im already doing a game with python :man_facepalming:

(Monster) #13

After adding a new object, it looses the relation to the status of the “origin”.

It individualy plays it’s actions.

In other words: you create an enemy which starts it’s idle animation. Some frames later you add another enemy from the same original. The second enemy starts it’s idle animation.

While both animations are the same (both due to the same logic) they do not play at the same time as you created them at different time. The difference bocaomes more visible when they discover different eventws at different time.

E.g. the first enemy hits a wall and has to turn, while the second one can still walk stright forward.

The setup is the same, the status is different.

When you want enemies with different idle animations either you make them available via different states (a decission, to play idle A or idle B), or you create a different origin you can add from. The first solution increases the “skills” of a single enemy type, while the second adds a new enemy type.

(blenderaptor) #14


Beside this. How do you usual control many ennemies in the same scene ? Do you “Add Object” them or do you create many objects (and then, coming with their own logic bricks) ?

I ask because, if they is some easy stuff to call : like ‘playAction’, python programm things like a Steering actuator might be more complex

(- Click for resources) #15

This is up to you, do you want to spend less resources (physics, calculation time, etc) on the objects or does it not matter to you? if it does, addObject if not then make as much duplicates as you like with their own set of bricks.

Also if you ‘kill’ an object does it need to respawn later? if so then addObject.

Not complex, you just need to know the name of the script.

obj.alignAxisToVect(vector/position to track to, the axis to point in the direction, rotation_speed)

Then simply give the obj some velocity/force/etc on the axis you want to track to and it will move that way.

so for example:

axis = 1 # 0=x,1=y,2=z
obj.alignAxisToVect(door.worldPosition, axis, 0.8)
obj.localLinearVelocity.y =1.4

(Monster) #16

What I would do:

I define a “character type” in an hidden layer. (Typically I place it in a group, but you do not need that). For example you have these types:

  • cat
  • dog
  • police officer A
  • police officer B

Then you can add one or more instances of the same type (e.g. two cats) . Each instance looks the same and has the same behavior (same logic, same actions). But they have different state:

  • cat.001 is at a different location than cat.002.
  • cat.001 is sleeping (sleeping animation) while cat.002 is hungry and walks around looking for food (walking animation).

You can create the instances at design time and at runtime.

Possible individual changes:

Mesh Replacement

You can indeed implement differences in the appearance, but you do that by changing the state. E.g. you could change the fur color state from gray to orange (e.g. setting a property). This by itself does nothing. The cat type needs logic that acts on the state change e.g. by replacing the mesh of the individual instance. This should be no big deal you can even do that with logic bricks.

Cloth changes

You can apply other changes that should deform with the armature (e.g. changing clothes or items) the same way, but you need at least an object (even withpout vertieces) to replace the mesh.

Gadgets / Items

If yout want to add non-deforming objects to bones (e.g. gadgets) you can (before start) bone-parent emtpies (=hooks) and dynamically parent objects to these hooks.


As said, you can’t exchange logic. But you could dynamically exchange parameters that control the logic. E.g. you set a property that makes the character tired faster, walking slower. Your logic should care of these properties (including reacting on updates), otherwise it will have no effect.


You need to be aware that non-local events such as keypresses, message, and so on will be recognised by all instances that are listening to this events. As all instances share the same logic this will always be the case. Example when all cats are listening to a they will all react on it when a is pressed. It is still individual but (assuming a means walk forward) all cats will walk forward at the same time. You will need to care the context of such an event.


An option would be to select the character. This way the logic needs to check the event and the selection status. So only selected cats will walk forward. This is often used at RPG games.


Another option is to select (or focus) with the context of the observer. E.g. you focus the cat at the center of the view (camera), or the cat near the players origin. This is often used at FPV-games.


The character types allows you to easily get quite a large number of characters in your scene. With the above options you can even individualize the characters of the same type, which will increase the variation. You still get of saving a lot of work.

But you need to be aware that this can result in side effects. When you change a character type all instances of this character type will inherit this change. This can be positive (= less work) or negative (= unwanted effects).

I hope it helps a bit

(blenderaptor) #17

thx Cotaks and Monster. I already investigated a bit on the subject. But i still far from implementing many AI :smiley: But i already have many ideas