Index: /code/branches/core5/src/libraries/core/BaseObject.cc
===================================================================
--- /code/branches/core5/src/libraries/core/BaseObject.cc	(revision 5886)
+++ /code/branches/core5/src/libraries/core/BaseObject.cc	(revision 5887)
@@ -245,5 +245,5 @@
 
     /**
-        @brief Adds an object which listens to the events of this object.
+        @brief Adds an object which listens to the events of this object. The events are sent to the other objects mainstate.
     */
     void BaseObject::addEventListener(BaseObject* listener)
@@ -268,4 +268,9 @@
     }
 
+    /**
+        @brief Adds a new event-state to the object. Event-states are states which can be changed by events.
+        @param name  The name of the event
+        @param state The object containing information about the event-state
+    */
     void BaseObject::addEventState(const std::string& name, EventState* state)
     {
@@ -280,4 +285,7 @@
     }
 
+    /**
+        @brief Returns the event-state with the given name.
+    */
     EventState* BaseObject::getEventState(const std::string& name) const
     {
@@ -406,3 +414,48 @@
         }
     }
+    
+    /**
+        @brief Manually loads all event states, even if the class doesn't officially support them. This is needed by some classes like @ref EventDispatcher or @ref EventTarget.
+    */
+    void BaseObject::loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier)
+    {
+        Element* events = xmlelement.FirstChildElement("events", false);
+        if (events)
+        {
+            // get the list of all states present
+            std::list<std::string> eventnames;
+            if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject)
+            {
+                for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++)
+                    eventnames.push_back(child->Value());
+            }
+            else if (mode == XMLPort::SaveObject)
+            {
+            }
+
+            // iterate through all states and get the event sources
+            for (std::list<std::string>::iterator it = eventnames.begin(); it != eventnames.end(); ++it)
+            {
+                std::string statename = (*it);
+
+                // if the event state is already known, continue with the next state
+                orxonox::EventState* eventstate = object->getEventState(statename);
+                if (eventstate)
+                    continue;
+
+                XMLPortClassObjectContainer<BaseObject, BaseObject>* container = (XMLPortClassObjectContainer<BaseObject, BaseObject>*)(identifier->getXMLPortObjectContainer(statename));
+                if (!container)
+                {
+                    ExecutorMember<BaseObject>* setfunctor = createExecutor(createFunctor(&BaseObject::addEventSource), std::string( "BaseObject" ) + "::" + "addEventSource" + "(" + statename + ")");
+                    ExecutorMember<BaseObject>* getfunctor = createExecutor(createFunctor(&BaseObject::getEventSource), std::string( "BaseObject" ) + "::" + "getEventSource" + "(" + statename + ")");
+                    setfunctor->setDefaultValue(1, statename);
+                    getfunctor->setDefaultValue(1, statename);
+
+                    container = new XMLPortClassObjectContainer<BaseObject, BaseObject>(statename, identifier, setfunctor, getfunctor, false, true);
+                    identifier->addXMLPortObjectContainer(statename, container);
+                }
+                container->port(object, *events, mode);
+            }
+        }
+    }
 }
Index: /code/branches/core5/src/libraries/core/BaseObject.h
===================================================================
--- /code/branches/core5/src/libraries/core/BaseObject.h	(revision 5886)
+++ /code/branches/core5/src/libraries/core/BaseObject.h	(revision 5887)
@@ -172,6 +172,19 @@
             /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */
             inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; }
+            
+            static void loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier);
 
         protected:
+            void addEventState(const std::string& name, EventState* container);
+            EventState* getEventState(const std::string& name) const;
+
+            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
+            std::string mainStateName_;
+            Functor*    mainStateFunctor_;
+
+        private:
             /** @brief Adds an object which listens to the events of this object. */
             inline void registerEventListener(BaseObject* object)
@@ -181,15 +194,4 @@
                 { this->eventListeners_.erase(object); }
 
-            void addEventState(const std::string& name, EventState* container);
-            EventState* getEventState(const std::string& name) const;
-
-            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
-            std::string mainStateName_;
-            Functor*    mainStateFunctor_;
-
-        private:
             void setXMLName(const std::string& name);
             Template* getTemplate(unsigned int index) const;
Index: /code/branches/core5/src/modules/objects/eventsystem/EventDispatcher.cc
===================================================================
--- /code/branches/core5/src/modules/objects/eventsystem/EventDispatcher.cc	(revision 5886)
+++ /code/branches/core5/src/modules/objects/eventsystem/EventDispatcher.cc	(revision 5887)
@@ -54,4 +54,7 @@
 
         XMLPortObject(EventDispatcher, BaseObject, "targets", addTarget, getTarget, xmlelement, mode);
+
+        // since we need event sources mapped to any state, we have to parse XML by ourselves
+        this->loadAllEventStates(xmlelement, mode, this, Class(EventDispatcher));
     }
 
Index: /code/branches/core5/src/modules/objects/eventsystem/EventTarget.cc
===================================================================
--- /code/branches/core5/src/modules/objects/eventsystem/EventTarget.cc	(revision 5886)
+++ /code/branches/core5/src/modules/objects/eventsystem/EventTarget.cc	(revision 5887)
@@ -29,4 +29,5 @@
 #include "EventTarget.h"
 #include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
 
 namespace orxonox
@@ -43,4 +44,12 @@
     }
     
+    void EventTarget::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(EventTarget, XMLPort, xmlelement, mode);
+
+        // since we need event sources mapped to any state, we have to parse XML by ourselves
+        this->loadAllEventStates(xmlelement, mode, this, Class(EventTarget));
+    }
+
     void EventTarget::processEvent(Event& event)
     {
Index: /code/branches/core5/src/modules/objects/eventsystem/EventTarget.h
===================================================================
--- /code/branches/core5/src/modules/objects/eventsystem/EventTarget.h	(revision 5886)
+++ /code/branches/core5/src/modules/objects/eventsystem/EventTarget.h	(revision 5887)
@@ -43,4 +43,6 @@
             virtual ~EventTarget();
             
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            
             virtual void processEvent(Event& event);
 
