Index: code/branches/objecthierarchy2/src/core/BaseObject.cc
===================================================================
--- code/branches/objecthierarchy2/src/core/BaseObject.cc	(revision 2212)
+++ code/branches/objecthierarchy2/src/core/BaseObject.cc	(revision 2254)
@@ -36,4 +36,5 @@
 #include "CoreIncludes.h"
 #include "EventIncludes.h"
+#include "Functor.h"
 #include "XMLPort.h"
 #include "XMLFile.h"
@@ -60,4 +61,7 @@
         this->oldGametype_ = 0;
 
+        this->functorSetMainState_ = 0;
+        this->functorGetMainState_ = 0;
+
         this->setCreator(creator);
         if (this->creator_)
@@ -82,9 +86,17 @@
     BaseObject::~BaseObject()
     {
-        for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
-            (*it)->unregisterEventListener(this);
-
-        for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
-            it->first->removeEvent(this);
+        if (this->isInitialized())
+        {
+            for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
+                (*it)->unregisterEventListener(this);
+
+            for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
+                it->first->removeEvent(this);
+
+            if (this->functorSetMainState_)
+                delete this->functorSetMainState_;
+            if (this->functorGetMainState_)
+                delete this->functorGetMainState_;
+        }
     }
 
@@ -100,4 +112,5 @@
         XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode);
         XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
+        XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode);
 
         XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
@@ -279,3 +292,46 @@
         SetEvent(BaseObject, "visibility", setVisible, event);
     }
+
+    void BaseObject::setMainStateName(const std::string& name)
+    {
+        if (this->mainStateName_ != name)
+        {
+            this->mainStateName_ = name;
+            if (this->functorSetMainState_)
+                delete this->functorSetMainState_;
+            if (this->functorGetMainState_)
+                delete this->functorGetMainState_;
+            this->changedMainState();
+            if (!this->functorSetMainState_)
+                COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl;
+        }
+    }
+
+    void BaseObject::setMainState(bool state)
+    {
+        if (this->functorSetMainState_)
+            (*this->functorSetMainState_)(state);
+        else
+            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
+    }
+
+    bool BaseObject::getMainState() const
+    {
+        if (this->functorGetMainState_)
+        {
+            (*this->functorGetMainState_)();
+            return this->functorGetMainState_->getReturnvalue();
+        }
+        else
+        {
+            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
+            return false;
+        }
+    }
+
+    void BaseObject::changedMainState()
+    {
+        SetMainState(BaseObject, "activity",   setActive,  isActive);
+        SetMainState(BaseObject, "visibility", setVisible, isVisible);
+    }
 }
Index: code/branches/objecthierarchy2/src/core/BaseObject.h
===================================================================
--- code/branches/objecthierarchy2/src/core/BaseObject.h	(revision 2212)
+++ code/branches/objecthierarchy2/src/core/BaseObject.h	(revision 2254)
@@ -36,4 +36,11 @@
 #ifndef _BaseObject_H__
 #define _BaseObject_H__
+
+#define SetMainState(classname, statename, setfunction, getfunction) \
+    if (this->getMainStateName() == statename) \
+    { \
+        this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \
+        this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \
+    }
 
 #include <map>
@@ -100,4 +107,11 @@
             virtual void changedVisibility() {}
 
+            void setMainState(bool state);
+            bool getMainState() const;
+
+            void setMainStateName(const std::string& name);
+            inline const std::string& getMainStateName() const { return this->mainStateName_; }
+            virtual void changedMainState();
+
             /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */
             inline void setFile(const XMLFile* file) { this->file_ = file; }
@@ -153,6 +167,9 @@
             std::string name_;                          //!< The name of the object
             std::string oldName_;                       //!< The old name of the object
-            mbool bActive_;                             //!< True = the object is active
-            mbool bVisible_;                            //!< True = the object is visible
+            mbool       bActive_;                       //!< True = the object is active
+            mbool       bVisible_;                      //!< True = the object is visible
+            std::string mainStateName_;
+            Functor*    functorSetMainState_;
+            Functor*    functorGetMainState_;
 
         private:
@@ -160,14 +177,14 @@
             Template* getTemplate(unsigned int index) const;
 
-            bool                  bInitialized_;         //!< True if the object was initialized (passed the object registration)
-            const XMLFile*        file_;                 //!< The XMLFile that loaded this object
-            std::string           loaderIndentation_;    //!< Indentation of the debug output in the Loader
-            Namespace*            namespace_;
-            BaseObject*           creator_;
-            Scene*                scene_;
-            Gametype*             gametype_;
-            Gametype*             oldGametype_;
-            std::set<Template*>   templates_;
-            std::map<BaseObject*, std::string> eventListeners_;
+            bool                   bInitialized_;         //!< True if the object was initialized (passed the object registration)
+            const XMLFile*         file_;                 //!< The XMLFile that loaded this object
+            std::string            loaderIndentation_;    //!< Indentation of the debug output in the Loader
+            Namespace*             namespace_;
+            BaseObject*            creator_;
+            Scene*                 scene_;
+            Gametype*              gametype_;
+            Gametype*              oldGametype_;
+            std::set<Template*>    templates_;
+            std::map<BaseObject*,  std::string> eventListeners_;
             std::list<BaseObject*> events_;
             std::map<std::string, EventContainer*> eventContainers_;
@@ -178,4 +195,5 @@
     SUPER_FUNCTION(3, BaseObject, changedVisibility, false);
     SUPER_FUNCTION(4, BaseObject, processEvent, false);
+    SUPER_FUNCTION(6, BaseObject, changedMainState, false);
 }
 
Index: code/branches/objecthierarchy2/src/core/Functor.h
===================================================================
--- code/branches/objecthierarchy2/src/core/Functor.h	(revision 2212)
+++ code/branches/objecthierarchy2/src/core/Functor.h	(revision 2254)
@@ -167,5 +167,5 @@
             }
 
-            FunctorMember* setObject(T* object)
+            FunctorMember<T>* setObject(T* object)
             {
                 this->bConstObject_ = false;
@@ -174,5 +174,5 @@
             }
 
-            FunctorMember* setObject(const T* object)
+            FunctorMember<T>* setObject(const T* object)
             {
                 this->bConstObject_ = true;
Index: code/branches/objecthierarchy2/src/core/Super.h
===================================================================
--- code/branches/objecthierarchy2/src/core/Super.h	(revision 2212)
+++ code/branches/objecthierarchy2/src/core/Super.h	(revision 2254)
@@ -236,4 +236,7 @@
     #define SUPER_changedScale(classname, functionname, ...) \
         SUPER_NOARGS(classname, functionname)
+
+    #define SUPER_changedMainState(classname, functionname, ...) \
+        SUPER_NOARGS(classname, functionname)
     // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
 
@@ -448,4 +451,8 @@
             ()
         SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
+
+        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedMainState, false)
+            ()
+        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
         // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
 
@@ -496,4 +503,5 @@
     SUPER_INTRUSIVE_DECLARATION(processEvent);
     SUPER_INTRUSIVE_DECLARATION(changedScale);
+    SUPER_INTRUSIVE_DECLARATION(changedMainState);
     // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
 
