diff --git a/Source/Editor/Utilities/EditorScene.cpp b/Source/Editor/Utilities/EditorScene.cpp new file mode 100644 index 000000000..4350a31ff --- /dev/null +++ b/Source/Editor/Utilities/EditorScene.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. + +#include "EditorScene.h" + +EditorScene::EditorScene(const SpawnParams& params) + : Scene(params) +{ + // Mock editor preview scene to be in gameplay + EditorScene::PostSpawn(); + SceneBeginData beginData; + EditorScene::BeginPlay(&beginData); + beginData.OnDone(); +} + +void EditorScene::Update() +{ + for (auto& e : Ticking.Update.Ticks) + e.Call(); + for (auto& e : Ticking.LateUpdate.Ticks) + e.Call(); + for (auto& e : Ticking.FixedUpdate.Ticks) + e.Call(); +} diff --git a/Source/Editor/Utilities/EditorScene.h b/Source/Editor/Utilities/EditorScene.h new file mode 100644 index 000000000..998ec0141 --- /dev/null +++ b/Source/Editor/Utilities/EditorScene.h @@ -0,0 +1,19 @@ +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. + +#pragma once + +#include "Engine/Level/Scene/Scene.h" + +/// +/// Scene for editor previews with support of object drawing and updating in separation of global scenes collection. It mocks the gameplay to preview scene objects. +/// +API_CLASS() class EditorScene final : public Scene +{ +DECLARE_SCENE_OBJECT(EditorScene); +public: + + /// + /// Updates the gameplay. + /// + API_FUNCTION() void Update(); +}; diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index 324e6ada1..42e937976 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -198,7 +198,7 @@ void Actor::SetParent(Actor* value, bool worldPositionsStays, bool canBreakPrefa // Check if value won't change if (_parent == value) return; - if (!IsInMainThread()) + if (IsDuringPlay() && !IsInMainThread()) { LOG(Error, "Editing scene hierarchy is only allowed on a main thread."); return; diff --git a/Source/Engine/Level/Scene.cs b/Source/Engine/Level/Scene.cs index c4b92a6bc..da8cd978d 100644 --- a/Source/Engine/Level/Scene.cs +++ b/Source/Engine/Level/Scene.cs @@ -2,7 +2,7 @@ namespace FlaxEngine { - public sealed partial class Scene + partial class Scene { /// /// The scene asset typename. Type of the serialized scene asset data. Hidden class for the scene assets. Actors deserialization rules are strictly controlled under the hood by the C++ core parts. Mostly because scene asset has the same ID as scene root actor so loading both managed objects for scene asset and scene will crash (due to object ids conflict). diff --git a/Source/Engine/Level/Scene/Scene.h b/Source/Engine/Level/Scene/Scene.h index d3c1502c6..c576e7eca 100644 --- a/Source/Engine/Level/Scene/Scene.h +++ b/Source/Engine/Level/Scene/Scene.h @@ -19,7 +19,7 @@ class NavMesh; /// /// The scene root object that contains a hierarchy of actors. /// -API_CLASS() class FLAXENGINE_API Scene final : public Actor +API_CLASS() class FLAXENGINE_API Scene : public Actor { DECLARE_SCENE_OBJECT(Scene); friend Level;