Spawning Lazy Actors EN - Drova-Modding/Drova-Modding-API GitHub Wiki
A Lazy Actor is a performance approach for a normal NPC/Creature. It is by itself only one GameObject with a Listener to where the Player is and when the player comes into its detection zone, it will initialize fully. If the Player leaves, it will also deinit.
using Drova_Modding_API.Access;
using Drova_Modding_API.Systems.Spawning;
void Somewhere() {
LazyActorCreator.LazyActorParams lazyActorParams = new()
{
AssetReference = AddressableAccess.Creatures.BabyRedFox,
// If you set this to true, you need also to set MaxHealth and CurrentHealth
HasCustomHealth = false,
EntityInfo = AddressableAccess.EntityInfos.EntityInfo_NPC_BabyRedFox,
// WorldPosition alternativ you can use the ActorWorldLocator to get a random spawn point near the player. Btw. Position 0,0,0 is at the entrance of the ruin camp by the cave where the priest and alchemist is
Position = new Vector3(0, 0, 0),
};
// The LazyActor is not fully generated yet, we need to load in the background the EntityInfo and setup some other things, but it will not take
// long and mostly you will not need a reference probably.
Il2CppDrova.Utilities.LazyLoading.LazyActor createdActor = LazyActorCreator.CreateLazyActorCreature(lazyActorParams);
}
To make the Actor Persistent you just need to get the LazyActorStore. Please be aware that this means, that the LazyActors are persistent in the save game. You could give them a unique Name to find them later on or over the EntityGameHandler
you can get them by Guid and could remove them, if they are getting out of control.
using Drova_Modding_API.Systems.SaveGame;
using Drova_Modding_API.Systems.SaveGame.Store;
using Drova_Modding_API.Systems.Spawning;
void Somewhere() {
// ...
Il2CppDrova.Utilities.LazyLoading.LazyActor createdActor = LazyActorCreator.CreateLazyActorCreature(lazyActor);
IStore<LazyActorSaveData> lazyActorStore = SaveGameSystem.Instance.GetStore<LazyActorSaveData>();
lazyActorStore.Add(new LazyActorSaveData(LazyActorCreator.LAZY_ACTOR_NAME, lazyActorParams.AssetReference.AssetGUID, lazyActorParams.EntityInfo.AssetGUID, createdActor._guidstring));
}