Active Game Objects, Passive Game Objects and Manager

Hi,

I want to explain the difference between passive and active game objects. What they are and when to use them. This is in my mind quite some time. I hope I can express it in an understandable way.

This thread discusses Game Objects only (it does not discuss the interaction to Physics, Rendering or other parts of the BGE).

What is an Active Game Object?



An Active Game Object processes the logic of a feature on itself. It extracts data from itself and it modifies its own states. It behaves as a Single Object.

What is a Passive Game Object?


A Passive Game Object is an object whose logic is processed by another game object. This means the data is extracted by another game object and modified by another game object.
The active object that performs the logic on the Passive Object is a Manager.
In terms of programming the passive game object behaves like data. The processing belongs to the manager (an active game object).

Can a game object be active and passive?


This means the object itself performs logic and another object performs logic on it.

If both processes perform the same logic this situation creates a conflict. It is strongly advised to avoid such conflicts as it easily leads to unpredictable results.
Therefore it is important to decide early if active or passive processing is used.

If active and passive logic perform different tasks the logic is independent from each other (separation of concerns). If seen separately the object will be active for one processing and passive for the other processing .

Example:

A) Selection processing:

Selection logic can be performed by a SelectionManager. The SelectionManager performs a centralized selection process. All UI regarding selection will be processed by the SelectionManager. The SelectionManager knows what objects are selected.
The SelectionManager deals with other game objects. In terms of selection processing these game objects are passive as they do not add any logic to the selection process.

A’)Alternative Selection process:
The game objects perform the selection process by them self. Each one can have an individual processing.

B) Selection Visualization:
Each game object can process it’s own selection visualization logic (it shows that it is selected or not). This makes the game objects active in terms of selection visualization (but not in terms of selection processing).

Both the selection process and the selection visualization are two separate features. These features have a process dependency as the selection visualization needs the output of the selection process. None of them need to know how the other process works.

When to use what?
This is a difficult decision and strongly depends on the situation.

Using Managers:

  • there is a lot of repeated processing (e.g. The selection process is always the same on all selectable objects)
  • the process needs consistent processing (e.g Selection is always on <LMK>)

Single Objects:

  • the involved game objects require individual processing (e.g. a Door gets a different selection mark than a Character)
  • there is only one game object involved

If a Manager has to deal with a lot of exceptions it is better to split the processing. Better let each manager perform its own processing. Just make sure they uniquely identify the passive game objects they need. E.g. a Selection manager for waypoints and a Selection manager for characters.

[Edit]
The method to manage (several) equal behaving objects is summarized in the Flyweight pattern

Nice to know. I like your presentations, Monster. They’re professional and informative. I should try to think ahead when I implement game objects, and consider both types before I define their AI.

Good to see that it helps a bit :).

AI is a good example too.

Managers for character types e.g. sword fighters vs. a set of sword fighters with own logic.

wery well explain

and good things to know. :wink:

This is very nice, Monster. Your visual aids always make things very clear - and they look great!

This reminds me of how much easier logic/programming becomes if you create a flowchart.

Thanks and great explaination monster, its quite hard to undersntand the whole concept to me, but I think that I got what you ment!

Thanks Monster.

Great stuff as always Monster! This reassured me in the use of passive logic.

Yeah , a manager always helps a lot . I use it in my games and I like it because of how easy it is to tweak things if needed.

Thanks again, Monster! Learned!
Please continue writing more of these stuffs …and also pdfs…(I’m so greedy:p)

As you all find this useful, I move it to the resource section… done.

It is linked from my guides page already ;).

again great Monster, very good this TD!

i recently get trhouble in a situation similar that you say “dangerous” mix active/passive (in fact) .

basically there 2 NPCs (obj active) then one a certain point attack the other , and should start a syncronizated action.
since have a action managed physically (from bullet) is impossible.
in this case i guess the the best way is make one obj decisely passive while the other still active (the attacker)
anyway again i not found the good way to give the order without “owerride” (the obj active write inside the code of other obj and make it passive)
now try with something as “messages” but is a thing never used before, anyway should be less “invasive”

Have them both use a sequencer ?

Object 1 (sequencer) -
properties
Animation - name of animation
Actor “Attacker”
Actor “Defender”
Frame

and then have a logic for loop like the .blend below to handle there actions?
(note that the action is set to property mode)
So the animations WILL not advance unless the property does

triggered by the “impact” of a collsion check from the attacker
so the impact feeds “attacker” and “defender” to the “sequencer” and sets “shared animation” to “TRUE”

the sequencer then changes it’s property “Frame” +1 every frame until the animation is done

So the attacker needs

property “shared animation” = True -----------------and-------------------Copy property “Anim” from “Frame”

otherwise he controlls his own animations,

Attachments

LogicDoorKey.blend (454 KB)

@BPR:

yes i have done something similar (but not use more frame property not recall well, if is broken or what other)

anyway with two character there more dependences .

you use physics, and you can keep all object “active” , not there conflict
since bullet do the work for you

with two character is not possible and give some dependences.

anyway i use a property “occuped” :smiley: (that is a evolution of simple parent),
when is True other characters cannot attack.

and work perfectly , my bad was keep both obj “half active”, but as say Monster it give conflict
anything easy to manage.

better a abrupt separation of task , not much realistic but much more easy.
:wink:

With two NPCs I suggest to use a “notify” method as you already suggest.

The notification can be:

  • a property set
  • a message send

The listeners are listening to:

  • property value
  • message subject

This way they can trigger their controllers at the same frame (active object).
Using messages is pretty save as long as not involved listeners can deal with unnecessary notification.

If you use properties it is a common method to reset the property after dealing with the notification. E.g. set True to notify (by notifier), set False after dealing with notification (by listener). This can lead to conflicts is a notifier sets the property and the listener resets the property at the same frame.
Solution: use an integer property and increase the value on notification. A property sensor can trigger the according controllers on value change. The listener does not need to reset the value (= no conflict at all).

I hope this is somehow understandable.