From ffd000c84900a5c07893ec1cc92f28a1d652753f Mon Sep 17 00:00:00 2001 From: Arkensor Date: Mon, 12 Feb 2024 18:29:58 +0100 Subject: [PATCH] Fix non main game world entities being tracked in persistence #30 --- src/Scripts/Game/EPF_EntitySaveData.c | 20 ++++++++++++++------ src/Scripts/Game/EPF_PersistenceComponent.c | 4 ++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Scripts/Game/EPF_EntitySaveData.c b/src/Scripts/Game/EPF_EntitySaveData.c index f696458..3977b45 100644 --- a/src/Scripts/Game/EPF_EntitySaveData.c +++ b/src/Scripts/Game/EPF_EntitySaveData.c @@ -70,9 +70,13 @@ class EPF_EntitySaveData : EPF_MetaDataDbEntity if (EPF_BitFlags.CheckFlags(flags, EPF_EPersistenceFlags.ROOT) && attributes.m_bSaveRemainingLifetime) { - auto garbage = ChimeraWorld.CastFrom(entity.GetWorld()).GetGarbageManager(); - if (garbage) - m_fRemainingLifetime = garbage.GetRemainingLifetime(entity); + auto garbageWorld = ChimeraWorld.CastFrom(entity.GetWorld()); + if (garbageWorld) + { + auto garbage = garbageWorld.GetGarbageManager(); + if (garbage) + m_fRemainingLifetime = garbage.GetRemainingLifetime(entity); + } if (m_fRemainingLifetime == -1) { @@ -146,9 +150,13 @@ class EPF_EntitySaveData : EPF_MetaDataDbEntity // Lifetime if (attributes.m_bSaveRemainingLifetime) { - auto garbage = ChimeraWorld.CastFrom(entity.GetWorld()).GetGarbageManager(); - if (garbage && m_fRemainingLifetime > 0) - garbage.Insert(entity, m_fRemainingLifetime); + auto garbageWorld = ChimeraWorld.CastFrom(entity.GetWorld()); + if (garbageWorld) + { + auto garbage = garbageWorld.GetGarbageManager(); + if (garbage && m_fRemainingLifetime > 0) + garbage.Insert(entity, m_fRemainingLifetime); + } } // Components diff --git a/src/Scripts/Game/EPF_PersistenceComponent.c b/src/Scripts/Game/EPF_PersistenceComponent.c index 977f492..81d6eea 100644 --- a/src/Scripts/Game/EPF_PersistenceComponent.c +++ b/src/Scripts/Game/EPF_PersistenceComponent.c @@ -303,6 +303,10 @@ // Persistence logic only runs on the server if (!EPF_PersistenceManager.IsPersistenceMaster()) return; + + // Avoid tracking anything in preload/preview world + if (!ChimeraWorld.CastFrom(owner.GetWorld()) || (GetGame().GetWorld() != owner.GetWorld())) + return; // Init and validate settings on shared class-class instance once EPF_PersistenceComponentClass settings = EPF_PersistenceComponentClass.Cast(GetComponentData(owner));