diff --git a/docs/API/unreal.md b/docs/API/unreal.md index cd8cd69..8016099 100644 --- a/docs/API/unreal.md +++ b/docs/API/unreal.md @@ -49,6 +49,7 @@ any regular `Service`: |`GetKFGameRI()` | Returns current game's `GameReplicationInfo` as `KFGameReplicationInfo`. | |`GetGameType()` | Returns current game's `GameInfo`. | |`GetKFGameType()` | Returns current game's `GameInfo` as `KFGameType`. | +|`FindActorInstance(class)` | Searches all `Actor`s on the level for an instance of specific class and returns it. | |`GetLocalPlayer()` | Returns current local player's `Controller`. | |`GetInventoryFrom(class, Inventory, optional bool)` | Convenience method for finding a first inventory entry of the given class in the given inventory chain. | |`GetAllInventoryFrom(class, Inventory, optional bool)` | Convenience method for finding a all inventory entries of the given class in the given inventory chain. | diff --git a/sources/Unreal/UnrealAPI.uc b/sources/Unreal/UnrealAPI.uc index 7ab7967..cb93885 100644 --- a/sources/Unreal/UnrealAPI.uc +++ b/sources/Unreal/UnrealAPI.uc @@ -164,6 +164,28 @@ public final function KFGameType GetKFGameType() return KFGameType(GetGameType()); } +/** + * Searches all `Actor`s on the level for an instance of specific class and + * returns it. + * + * @param classToFind Class we want to find an instance of. + * @result A pre-existing instance of class `classToFind`, `none` if + * no instances exist at the moment of this method's call. + */ +public final function Actor FindActorInstance(class classToFind) +{ + local Actor result; + local Service service; + service = class'CoreService'.static.Require(); + foreach service.AllActors(classToFind, result) + { + if (result != none) { + break; + } + } + return result; +} + /** * Returns current local player's `Controller`. Useful because `level` * is not accessible inside objects.