Skip to content

Commit

Permalink
Add option to request navmesh rebuild
Browse files Browse the repository at this point in the history
Fixes #17
  • Loading branch information
Arkensor committed Jul 17, 2023
1 parent 8e96e1c commit a8e7f95
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Scripts/Game/EPF_PersistenceComponent.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
[Attribute(defvalue: "1", desc: "If enabled the entity will deleted from persistence when deleted from the world automatically.")]
bool m_bSelfDelete;

[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.")]
bool m_bUpdateNavmesh;

[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).")]
bool m_bStorageRoot;

Expand Down Expand Up @@ -266,6 +269,9 @@
}
else
{
if (settings.m_bUpdateNavmesh)
UpdateNavesh();

if (m_pOnAfterLoad)
m_pOnAfterLoad.Invoke(this, saveData);
}
Expand Down Expand Up @@ -412,7 +418,7 @@
{
if (!parent)
return; // Maybe parent got deleted by the time this invokes on next frame

array<Managed> outComponents();
parent.FindComponents(SlotManagerComponent, outComponents);
foreach (Managed componentRef : outComponents)
Expand Down Expand Up @@ -694,10 +700,22 @@
//------------------------------------------------------------------------------------------------
protected void DeferredApplyCallback(EPF_EntitySaveData saveData)
{
EPF_PersistenceComponentClass settings = EPF_PersistenceComponentClass.Cast(GetComponentData(GetOwner()));
if (settings.m_bUpdateNavmesh)
UpdateNavesh();

if (m_pOnAfterLoad)
m_pOnAfterLoad.Invoke(this, saveData);
}

//------------------------------------------------------------------------------------------------
protected void UpdateNavesh()
{
SCR_AIWorld aiworld = SCR_AIWorld.Cast(GetGame().GetAIWorld());
if (aiworld)
aiworld.RequestNavmeshRebuildEntity(GetOwner());
}

#ifdef WORKBENCH
//------------------------------------------------------------------------------------------------
override event void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
Expand Down

0 comments on commit a8e7f95

Please sign in to comment.