SKSE Plugin Development/Iterating all Actors/NPCs

From the CreationKit Wiki
Jump to navigation Jump to search

Similar to "Cloak Scanning" in Papyrus, but way less expensive in terms of performance.

const auto processLists = RE::ProcessLists::GetSingleton();
if (!processLists) { return; }

const auto *ActorTypeNPC = RE::TESForm::LookupByEditorID<RE::BGSKeyword>("ActorTypeNPC");

for (auto &targetHandle: processLists->highActorHandles) {
   const auto actorPtr = targetHandle.get();
   if (!actorPtr) { continue; }

   // Check if actor is NPC (leave out if you want all actors)
   const auto base = actorPtr->GetActorBase();
   if (base && !base->GetRace()->HasKeyword(ActorTypeNPC)) {
       continue;
   }

   // Your code here
}

See Also[edit | edit source]