Skip to content

Commit a8e7f95

Browse files
committed
Add option to request navmesh rebuild
Fixes #17
1 parent 8e96e1c commit a8e7f95

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Scripts/Game/EPF_PersistenceComponent.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
[Attribute(defvalue: "1", desc: "If enabled the entity will deleted from persistence when deleted from the world automatically.")]
1414
bool m_bSelfDelete;
1515

16+
[Attribute(defvalue: "0", desc: "Update the navmesh on being loaded back into the world. Only makes sense for prefabs that can affect the navmesh - e.g. houses.")]
17+
bool m_bUpdateNavmesh;
18+
1619
[Attribute(defvalue: "1", desc: "Only storage root entities can be saved in the open world.\nIf disabled the entity will only be saved if inside another storage root (e.g. character, vehicle).")]
1720
bool m_bStorageRoot;
1821

@@ -266,6 +269,9 @@
266269
}
267270
else
268271
{
272+
if (settings.m_bUpdateNavmesh)
273+
UpdateNavesh();
274+
269275
if (m_pOnAfterLoad)
270276
m_pOnAfterLoad.Invoke(this, saveData);
271277
}
@@ -412,7 +418,7 @@
412418
{
413419
if (!parent)
414420
return; // Maybe parent got deleted by the time this invokes on next frame
415-
421+
416422
array<Managed> outComponents();
417423
parent.FindComponents(SlotManagerComponent, outComponents);
418424
foreach (Managed componentRef : outComponents)
@@ -694,10 +700,22 @@
694700
//------------------------------------------------------------------------------------------------
695701
protected void DeferredApplyCallback(EPF_EntitySaveData saveData)
696702
{
703+
EPF_PersistenceComponentClass settings = EPF_PersistenceComponentClass.Cast(GetComponentData(GetOwner()));
704+
if (settings.m_bUpdateNavmesh)
705+
UpdateNavesh();
706+
697707
if (m_pOnAfterLoad)
698708
m_pOnAfterLoad.Invoke(this, saveData);
699709
}
700710

711+
//------------------------------------------------------------------------------------------------
712+
protected void UpdateNavesh()
713+
{
714+
SCR_AIWorld aiworld = SCR_AIWorld.Cast(GetGame().GetAIWorld());
715+
if (aiworld)
716+
aiworld.RequestNavmeshRebuildEntity(GetOwner());
717+
}
718+
701719
#ifdef WORKBENCH
702720
//------------------------------------------------------------------------------------------------
703721
override event void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)

0 commit comments

Comments
 (0)