Clean up behaviors properly when moving levels
Also adds support for foreach loops with the behavior iterator.
This commit is contained in:
parent
ad87477650
commit
1e05bb2a55
6 changed files with 55 additions and 2 deletions
|
|
@ -716,6 +716,44 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, ClearBehaviors, ClearBehaviors)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void AActor::UnlinkBehaviorsFromLevel()
|
||||
{
|
||||
TArray<FName> toRemove = {};
|
||||
|
||||
TMap<FName, DBehavior*>::Iterator it = { Behaviors };
|
||||
TMap<FName, DBehavior*>::Pair* pair = nullptr;
|
||||
while (it.NextPair(pair))
|
||||
{
|
||||
auto b = pair->Value;
|
||||
if (b == nullptr || (b->ObjectFlags & OF_EuthanizeMe))
|
||||
toRemove.Push(pair->Key);
|
||||
else
|
||||
b->Level->RemoveActorBehavior(*b);
|
||||
}
|
||||
|
||||
for (auto& type : toRemove)
|
||||
RemoveBehavior(*PClass::FindClass(type));
|
||||
}
|
||||
|
||||
void AActor::LinkBehaviorsToLevel()
|
||||
{
|
||||
TArray<FName> toRemove = {};
|
||||
|
||||
TMap<FName, DBehavior*>::Iterator it = { Behaviors };
|
||||
TMap<FName, DBehavior*>::Pair* pair = nullptr;
|
||||
while (it.NextPair(pair))
|
||||
{
|
||||
auto b = pair->Value;
|
||||
if (b == nullptr || (b->ObjectFlags & OF_EuthanizeMe))
|
||||
toRemove.Push(pair->Key);
|
||||
else
|
||||
Level->AddActorBehavior(*b);
|
||||
}
|
||||
|
||||
for (auto& type : toRemove)
|
||||
RemoveBehavior(*PClass::FindClass(type));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// AActor::InStateSequence
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue