Index: /code/branches/core2/src/orxonox/core/BaseObject.h
===================================================================
--- /code/branches/core2/src/orxonox/core/BaseObject.h	(revision 878)
+++ /code/branches/core2/src/orxonox/core/BaseObject.h	(revision 879)
@@ -79,5 +79,5 @@
             const std::string& getLevelfile() const;
 
-            inline void setNamespace(Namespace* ns) { this->namespace_ = ns; }
+            virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; }
             inline Namespace* getNamespace() const { return this->namespace_; }
 
Index: /code/branches/core2/src/orxonox/core/Namespace.cc
===================================================================
--- /code/branches/core2/src/orxonox/core/Namespace.cc	(revision 878)
+++ /code/branches/core2/src/orxonox/core/Namespace.cc	(revision 879)
@@ -38,5 +38,5 @@
         RegisterObject(Namespace);
 
-        this->representingNamespace_ = 0;
+        this->representingNamespace_ = this;
     }
 
@@ -55,10 +55,28 @@
         BaseObject::XMLPort(xmlelement, loading);
 
-        XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true);
+        XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true, false);
     }
 
     void Namespace::loadObjects(BaseObject* object)
     {
-        object->setNamespace(this);
+        object->setNamespace(this->representingNamespace_);
+
+        if (object->isA(Class(Namespace)))
+            this->addSubnamespace((Namespace*)object);
+    }
+
+    void Namespace::addSubnamespace(Namespace* ns)
+    {
+        std::string name = ns->getName().substr(ns->getName().find("::"
+
+        if (!this->hasSubnamespace(ns->getName()))
+            this->namespaces_[ns->getName()] = ns;
+        else
+            ns->representingNamespace_ = object;
+    }
+
+    bool Namespace::hasSubnamespace(const std::string& name) const
+    {
+        return (this->namespaces_.find(name) != this->namespaces_.end());
     }
 
Index: /code/branches/core2/src/orxonox/core/Namespace.h
===================================================================
--- /code/branches/core2/src/orxonox/core/Namespace.h	(revision 878)
+++ /code/branches/core2/src/orxonox/core/Namespace.h	(revision 879)
@@ -29,5 +29,5 @@
 #define _Namespace_H__
 
-#include <list>
+#include <map>
 
 #include "BaseObject.h"
@@ -49,6 +49,9 @@
             const BaseObject* saveObjects(unsigned int index) const;
 
+            void addSubnamespace(Namespace* ns);
+            bool hasSubnamespace(const std::string& name) const;
+
         private:
-            std::list<Namespace*> namespaces_;
+            std::map<std::string, Namespace*> namespaces_;
             Namespace* representingNamespace_;
     };
Index: /code/branches/core2/src/orxonox/core/XMLPort.h
===================================================================
--- /code/branches/core2/src/orxonox/core/XMLPort.h	(revision 878)
+++ /code/branches/core2/src/orxonox/core/XMLPort.h	(revision 879)
@@ -59,9 +59,9 @@
     xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading)
 
-#define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading, bApplyLoaderMask) \
+#define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading, bApplyLoaderMask, bLoadBefore) \
     orxonox::XMLPortClassObjectContainer<classname, objectclass>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassObjectContainer<classname, objectclass>*)(this->getIdentifier()->getXMLPortObjectContainer(sectionname)); \
     if (!xmlcontainer##loadfunction##savefunction) \
     { \
-        xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(this->getIdentifier()->getName(), std::string(sectionname), &classname::loadfunction, &classname::savefunction, bApplyLoaderMask); \
+        xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(this->getIdentifier()->getName(), std::string(sectionname), &classname::loadfunction, &classname::savefunction, bApplyLoaderMask, bLoadBefore); \
         this->getIdentifier()->addXMLPortObjectContainer(sectionname, xmlcontainer##loadfunction##savefunction); \
     } \
@@ -202,4 +202,5 @@
             std::string sectionname_;
             bool bApplyLoaderMask_;
+            bool bLoadBefore_;
 
         private:
@@ -212,5 +213,5 @@
     {
         public:
-            XMLPortClassObjectContainer(const std::string classname, const std::string sectionname, void (T::*loadfunction)(O*), const O* (T::*savefunction)(unsigned int) const, bool bApplyLoaderMask)
+            XMLPortClassObjectContainer(const std::string classname, const std::string sectionname, void (T::*loadfunction)(O*), const O* (T::*savefunction)(unsigned int) const, bool bApplyLoaderMask, bool bLoadBefore)
             {
                 this->classname_ = classname;
@@ -219,4 +220,5 @@
                 this->savefunction_ = savefunction;
                 this->bApplyLoaderMask_ = bApplyLoaderMask;
+                this->bLoadBefore_ = bLoadBefore;
             }
 
@@ -248,7 +250,11 @@
                                             newObject->setLoaderIndentation(object->getLoaderIndentation() + "  ");
                                             newObject->setLevel(object->getLevel());
-                                            newObject->XMLPort(*child, true);
+                                            newObject->setNamespace(object->getNamespace());
+                                            if (this->bLoadBefore_)
+                                                newObject->XMLPort(*child, true);
                                             COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl;
                                             (*object.*this->loadfunction_)(newObject);
+                                            if (!this->bLoadBefore_)
+                                                newObject->XMLPort(*child, true);
                                             COUT(5) << "  ...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl;
                                         }
Index: /code/branches/core2/src/orxonox/objects/WorldEntity.cc
===================================================================
--- /code/branches/core2/src/orxonox/objects/WorldEntity.cc	(revision 878)
+++ /code/branches/core2/src/orxonox/objects/WorldEntity.cc	(revision 879)
@@ -182,5 +182,5 @@
         XMLPortParam(WorldEntity, "rotationRate", setRotationRate, getRotationRate, xmlelement, loading);
 
-        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, loading, false);
+        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, loading, false, true);
     }
 
