Index: code/branches/objecthierarchy/src/core/BaseObject.cc
===================================================================
--- code/branches/objecthierarchy/src/core/BaseObject.cc	(revision 2013)
+++ code/branches/objecthierarchy/src/core/BaseObject.cc	(revision 2019)
@@ -47,5 +47,5 @@
         @brief Constructor: Registers the object in the BaseObject-list.
     */
-    BaseObject::BaseObject() : bInitialized_(false)
+    BaseObject::BaseObject(BaseObject* creator) : bInitialized_(false)
     {
         RegisterRootObject(BaseObject);
@@ -55,7 +55,21 @@
         this->bActive_ = true;
         this->bVisible_ = true;
+        this->oldGametype_ = 0;
 
-        this->file_ = 0;
-        this->namespace_ = 0;
+        this->setCreator(creator);
+        if (this->creator_)
+        {
+            this->setFile(this->creator_->getFile());
+            this->setNamespace(this->creator_->getNamespace());
+            this->setScene(this->creator_->getScene());
+            this->setGametype(this->creator_->getGametype());
+        }
+        else
+        {
+            this->file_ = 0;
+            this->namespace_ = 0;
+            this->scene_ = 0;
+            this->gametype_ = 0;
+        }
     }
 
@@ -79,5 +93,5 @@
         XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
 
-        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, const std::string&);
+        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
     }
 
@@ -91,5 +105,5 @@
             return this->file_->getFilename();
         else
-            return blankString;
+            return BLANKSTRING;
     }
 
Index: code/branches/objecthierarchy/src/core/BaseObject.h
===================================================================
--- code/branches/objecthierarchy/src/core/BaseObject.h	(revision 2013)
+++ code/branches/objecthierarchy/src/core/BaseObject.h	(revision 2019)
@@ -45,4 +45,7 @@
 namespace orxonox
 {
+    class Scene;
+    class Gametype;
+
     //! The BaseObject is the parent of all classes representing an instance in the game.
     class _CoreExport BaseObject : virtual public OrxonoxClass
@@ -51,5 +54,5 @@
 
         public:
-            BaseObject();
+            BaseObject(BaseObject* creator);
             virtual ~BaseObject();
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
@@ -96,4 +99,15 @@
             inline Namespace* getNamespace() const { return this->namespace_; }
 
+            inline void setCreator(BaseObject* creator) { this->creator_ = creator; }
+            inline BaseObject* getCreator() const { return this->creator_; }
+
+            inline void setScene(Scene* scene) { this->scene_ = scene; }
+            inline Scene* getScene() const { return this->scene_; }
+
+            inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); }
+            inline Gametype* getGametype() const { return this->gametype_; }
+            inline Gametype* getOldGametype() const { return this->oldGametype_; }
+            virtual inline void changedGametype() {}
+
             /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */
             inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; }
@@ -110,8 +124,12 @@
             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_;
+            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_;
     };
Index: code/branches/objecthierarchy/src/core/ClassFactory.h
===================================================================
--- code/branches/objecthierarchy/src/core/ClassFactory.h	(revision 2013)
+++ code/branches/objecthierarchy/src/core/ClassFactory.h	(revision 2019)
@@ -56,5 +56,5 @@
         public:
             static bool create(const std::string& name, bool bLoadable = true);
-            BaseObject* fabricate();
+            BaseObject* fabricate(BaseObject* creator);
 
         private:
@@ -63,5 +63,5 @@
             virtual ~ClassFactory() {}                      // Don't delete
 
-            static T* createNewObject();
+            static T* createNewObject(BaseObject* creator);
     };
 
@@ -88,7 +88,7 @@
     */
     template <class T>
-    BaseObject* ClassFactory<T>::fabricate()
+    BaseObject* ClassFactory<T>::fabricate(BaseObject* creator)
     {
-        return ClassFactory<T>::createNewObject();
+        return ClassFactory<T>::createNewObject(creator);
     }
 
@@ -98,7 +98,7 @@
     */
     template <class T>
-    T* ClassFactory<T>::createNewObject()
+    T* ClassFactory<T>::createNewObject(BaseObject* creator)
     {
-        return new T;
+        return new T(creator);
     }
 }
Index: code/branches/objecthierarchy/src/core/Factory.cc
===================================================================
--- code/branches/objecthierarchy/src/core/Factory.cc	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Factory.cc	(revision 2019)
@@ -104,5 +104,5 @@
         {
             // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
-            BaseObject* temp = (*it).second->fabricate();
+            BaseObject* temp = (*it).second->fabricate(0);
             delete temp;
         }
Index: code/branches/objecthierarchy/src/core/Factory.h
===================================================================
--- code/branches/objecthierarchy/src/core/Factory.h	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Factory.h	(revision 2019)
@@ -93,5 +93,5 @@
     {
         public:
-            virtual BaseObject* fabricate() = 0;
+            virtual BaseObject* fabricate(BaseObject* creator) = 0;
             virtual ~BaseFactory() {};
     };
Index: code/branches/objecthierarchy/src/core/Functor.h
===================================================================
--- code/branches/objecthierarchy/src/core/Functor.h	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Functor.h	(revision 2019)
@@ -106,5 +106,5 @@
             inline const MultiType& getReturnvalue() const { return this->returnedValue_; }
 
-            const std::string& getTypenameParam(unsigned int param) const { return (param < 5) ? this->typeParam_[param] : blankString; }
+            const std::string& getTypenameParam(unsigned int param) const { return (param < 5) ? this->typeParam_[param] : BLANKSTRING; }
             const std::string& getTypenameReturnvalue() const { return this->typeReturnvalue_; }
 
Index: code/branches/objecthierarchy/src/core/Identifier.cc
===================================================================
--- code/branches/objecthierarchy/src/core/Identifier.cc	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Identifier.cc	(revision 2019)
@@ -214,9 +214,9 @@
         @return The new object
     */
-    BaseObject* Identifier::fabricate()
+    BaseObject* Identifier::fabricate(BaseObject* creator)
     {
         if (this->factory_)
         {
-            return this->factory_->fabricate(); // We have to return a BaseObject, because we don't know the exact type.
+            return this->factory_->fabricate(creator); // We have to return a BaseObject, because we don't know the exact type.
         }
         else
Index: code/branches/objecthierarchy/src/core/Identifier.h
===================================================================
--- code/branches/objecthierarchy/src/core/Identifier.h	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Identifier.h	(revision 2019)
@@ -100,5 +100,5 @@
             inline void addFactory(BaseFactory* factory) { this->factory_ = factory; }
 
-            BaseObject* fabricate();
+            BaseObject* fabricate(BaseObject* creator);
             bool isA(const Identifier* identifier) const;
             bool isExactlyA(const Identifier* identifier) const;
@@ -502,5 +502,5 @@
                 @brief Overloading of the * operator: returns the assigned identifier.
             */
-            inline Identifier* operator*()
+            inline Identifier* operator*() const
             {
                 return this->identifier_;
@@ -527,7 +527,7 @@
                 @return The new object
             */
-            T* fabricate()
-            {
-                BaseObject* newObject = this->identifier_->fabricate();
+            T* fabricate(BaseObject* creator) const
+            {
+                BaseObject* newObject = this->identifier_->fabricate(creator);
 
                 // Check if the creation was successful
Index: code/branches/objecthierarchy/src/core/Loader.cc
===================================================================
--- code/branches/objecthierarchy/src/core/Loader.cc	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Loader.cc	(revision 2019)
@@ -144,5 +144,5 @@
 
             COUT(4) << "  creating root-namespace..." << std::endl;
-            Namespace* rootNamespace = new Namespace();
+            Namespace* rootNamespace = new Namespace(0);
             rootNamespace->setLoaderIndentation("    ");
             rootNamespace->setFile(file);
Index: code/branches/objecthierarchy/src/core/Namespace.cc
===================================================================
--- code/branches/objecthierarchy/src/core/Namespace.cc	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Namespace.cc	(revision 2019)
@@ -37,5 +37,5 @@
     CreateFactory(Namespace);
 
-    Namespace::Namespace() :
+    Namespace::Namespace(BaseObject* creator) : BaseObject(creator),
       bAutogeneratedFileRootNamespace_(false),
       bRoot_(false),
Index: code/branches/objecthierarchy/src/core/Namespace.h
===================================================================
--- code/branches/objecthierarchy/src/core/Namespace.h	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Namespace.h	(revision 2019)
@@ -42,5 +42,5 @@
     {
         public:
-            Namespace();
+            Namespace(BaseObject* creator);
             virtual ~Namespace();
 
Index: code/branches/objecthierarchy/src/core/Template.cc
===================================================================
--- code/branches/objecthierarchy/src/core/Template.cc	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Template.cc	(revision 2019)
@@ -38,5 +38,5 @@
     CreateFactory(Template);
 
-    Template::Template() : xmlelement_("")
+    Template::Template(BaseObject* creator) : BaseObject(creator), xmlelement_("")
     {
         RegisterObject(Template);
@@ -59,5 +59,11 @@
         XMLPortParam(Template, "baseclass", setBaseclass, getBaseclass, xmlelement, mode);
 
-        this->setXMLElement(*dynamic_cast<TiXmlElement*>(xmlelement.FirstChildElement(false)->GetTiXmlPointer()));
+        Element* element = xmlelement.FirstChildElement(false);
+        if (element)
+        {
+            TiXmlElement* tixmlelement = dynamic_cast<TiXmlElement*>(element->GetTiXmlPointer());
+            if (tixmlelement)
+                this->setXMLElement(*tixmlelement);
+        }
     }
 
Index: code/branches/objecthierarchy/src/core/Template.h
===================================================================
--- code/branches/objecthierarchy/src/core/Template.h	(revision 2013)
+++ code/branches/objecthierarchy/src/core/Template.h	(revision 2019)
@@ -42,5 +42,5 @@
     {
         public:
-            Template();
+            Template(BaseObject* creator);
             virtual ~Template();
 
Index: code/branches/objecthierarchy/src/core/XMLPort.h
===================================================================
--- code/branches/objecthierarchy/src/core/XMLPort.h	(revision 2013)
+++ code/branches/objecthierarchy/src/core/XMLPort.h	(revision 2019)
@@ -479,8 +479,8 @@
                                                 COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl;
 
-                                                BaseObject* newObject = identifier->fabricate();
+                                                BaseObject* newObject = identifier->fabricate((BaseObject*)object);
                                                 newObject->setLoaderIndentation(((BaseObject*)object)->getLoaderIndentation() + "  ");
-                                                newObject->setFile(((BaseObject*)object)->getFile());
-                                                newObject->setNamespace(((BaseObject*)object)->getNamespace());
+//                                                newObject->setFile(((BaseObject*)object)->getFile());
+//                                                newObject->setNamespace(((BaseObject*)object)->getNamespace());
 
                                                 if (this->bLoadBefore_)
@@ -515,5 +515,12 @@
                                 else
                                 {
-                                    COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a valid classname." << std::endl;
+                                    if (this->sectionname_ != "")
+                                    {
+                                        COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a valid classname." << std::endl;
+                                    }
+                                    else
+                                    {
+                                        // It's probably just another subsection
+                                    }
                                 }
                             }
