Skip to content

Commit

Permalink
Fix non main game world entities being tracked in persistence #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkensor committed Feb 12, 2024
1 parent 956b88e commit ffd000c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Scripts/Game/EPF_EntitySaveData.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Scripts/Game/EPF_PersistenceComponent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit ffd000c

Please sign in to comment.