Merge branch 'BugFixes' of https://github.com/NoriteSC/FlaxEngineFork into NoriteSC-BugFixes

# Conflicts:
#	Source/Engine/Networking/NetworkReplicator.cpp
This commit is contained in:
Wojtek Figat
2023-09-28 12:28:19 +02:00
6 changed files with 37 additions and 38 deletions

View File

@@ -993,7 +993,7 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
// /\ all above this has to be done on an any thread
// \/ all below this has to be done on multiple threads at once
{
PROFILE_CPU_NAMED("Deserialize");
@@ -1016,8 +1016,16 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
// Synchronize prefab instances (prefab may have objects removed or reordered so deserialized instances need to synchronize with it)
// TODO: resave and force sync scenes during game cooking so this step could be skipped in game
SceneObjectsFactory::SynchronizePrefabInstances(context, prefabSyncData);
// Cache transformations
{
PROFILE_CPU_NAMED("Cache Transform");
scene->OnTransformChanged();
}
// Initialize scene objects
{
PROFILE_CPU_NAMED("Initialize");
@@ -1039,13 +1047,6 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
}
}
// Cache transformations
{
PROFILE_CPU_NAMED("Cache Transform");
scene->OnTransformChanged();
}
// /\ all above this has to be done on an any thread
// \/ all below this has to be done on a main thread

View File

@@ -1221,14 +1221,14 @@ bool Prefab::SyncChangesInternal(PrefabInstancesData& prefabInstancesData)
{
ScopeLock lock(Locker);
_isCreatingDefaultInstance = true;
_defaultInstance = PrefabManager::SpawnPrefab(this, nullptr, &ObjectsCache, true);
_defaultInstance = PrefabManager::SpawnPrefab(this,Transform::Identity, nullptr, &ObjectsCache, true);
_isCreatingDefaultInstance = false;
}
// Instantiate prefab instance from prefab (default spawning logic)
// Note: it will get any added or removed objects from the nested prefabs
// TODO: try to optimize by using recreated default instance to ApplyAllInternal (will need special path there if apply is done with default instance to unlink it instead of destroying)
const auto targetActor = PrefabManager::SpawnPrefab(this, nullptr, nullptr, true);
const auto targetActor = PrefabManager::SpawnPrefab(this, Transform::Identity, nullptr, nullptr, true);
if (targetActor == nullptr)
{
LOG(Warning, "Failed to instantiate default prefab instance from changes synchronization.");

View File

@@ -76,7 +76,7 @@ Actor* Prefab::GetDefaultInstance()
_isCreatingDefaultInstance = true;
// Instantiate objects from prefab (default spawning logic)
_defaultInstance = PrefabManager::SpawnPrefab(this, nullptr, &ObjectsCache);
_defaultInstance = PrefabManager::SpawnPrefab(this, Transform::Identity, nullptr, &ObjectsCache);
_isCreatingDefaultInstance = false;
return _defaultInstance;

View File

@@ -39,42 +39,37 @@ PrefabManagerService PrefabManagerServiceInstance;
Actor* PrefabManager::SpawnPrefab(Prefab* prefab)
{
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
return SpawnPrefab(prefab, parent, nullptr);
return SpawnPrefab(prefab,Transform::Identity, parent, nullptr);
}
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Vector3& position)
{
auto instance = SpawnPrefab(prefab);
if (instance)
instance->SetPosition(position);
return instance;
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
return SpawnPrefab(prefab, Transform(position), parent, nullptr);
}
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Vector3& position, const Quaternion& rotation)
{
auto instance = SpawnPrefab(prefab);
if (instance)
instance->SetTransform(Transform(position, rotation, instance->GetScale()));
return instance;
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
return SpawnPrefab(prefab, Transform(position, rotation), parent, nullptr);
}
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Vector3& position, const Quaternion& rotation, const Vector3& scale)
{
auto instance = SpawnPrefab(prefab);
if (instance)
instance->SetTransform(Transform(position, rotation, scale));
return instance;
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
return SpawnPrefab(prefab, Transform(position, rotation, scale), parent, nullptr);
}
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Transform& transform)
{
auto instance = SpawnPrefab(prefab);
if (instance)
instance->SetTransform(transform);
return instance;
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
return SpawnPrefab(prefab, transform, parent, nullptr);
}
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, const void*>* objectsCache, bool withSynchronization)
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent)
{
return SpawnPrefab(prefab, Transform::Identity, parent, nullptr);
}
Actor* PrefabManager::SpawnPrefab(Prefab* prefab,const Transform& transform, Actor* parent, Dictionary<Guid, const void*>* objectsCache, bool withSynchronization)
{
PROFILE_CPU_NAMED("Prefab.Spawn");
if (prefab == nullptr)
@@ -183,6 +178,10 @@ Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid
if (parent)
parent->Children.Add(root);
//move root to right location
if (transform != Transform::Identity)
root->SetTransform(transform);
// Link actors hierarchy
for (int32 i = 0; i < sceneObjects->Count(); i++)
{

View File

@@ -70,20 +70,18 @@ API_CLASS(Static) class FLAXENGINE_API PrefabManager
/// <param name="prefab">The prefab asset.</param>
/// <param name="parent">The parent actor to add spawned object instance. Can be null to just deserialize contents of the prefab.</param>
/// <returns>The created actor (root) or null if failed.</returns>
API_FUNCTION() static Actor* SpawnPrefab(Prefab* prefab, Actor* parent)
{
return SpawnPrefab(prefab, parent, nullptr);
}
API_FUNCTION() static Actor* SpawnPrefab(Prefab* prefab, Actor* parent);
/// <summary>
/// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay).
/// </summary>
/// <param name="prefab">The prefab asset.</param>
/// <param name="transform">prefab instance transform.</param>
/// <param name="parent">The parent actor to add spawned object instance. Can be null to just deserialize contents of the prefab.</param>
/// <param name="objectsCache">The options output objects cache that can be filled with prefab object id mapping to deserialized object (actor or script).</param>
/// <param name="withSynchronization">True if perform prefab changes synchronization for the spawned objects. It will check if need to add new objects due to nested prefab modifications.</param>
/// <returns>The created actor (root) or null if failed.</returns>
static Actor* SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, const void*, HeapAllocation>* objectsCache, bool withSynchronization = false);
static Actor* SpawnPrefab(Prefab* prefab, const Transform& transform, Actor* parent, Dictionary<Guid, const void*, HeapAllocation>* objectsCache, bool withSynchronization = false);
#if USE_EDITOR