I’m building a living world game, and I’m working on giving NPCs the illusion of agenda: it should look to the player as if they’re moving around the world pursuing their own goals and lives, but obviously nothing is actually happening to an NPC unless the player actually comes near them, at which point they spawn and make like they’ve been there all along.
It seems like the only data I need to keep track of at all times are a reference to each NPC, that NPC’s state (at work, taking a nap), and that NPC’s location.
The first two are trivial, but I’m really debating with myself over how to quantify location, as nothing else in my game specifically needs this. Since AI logic centers around finding and using interactable objects like in The Sims, the best idea I’ve had is to child every interactable Actor in a room to some master objectManager Actor, whose only job is to retain a reference to the interactables childed to it. When the game starts my master AI controller can generate a list of every objectManager in the game, and whenever the chunk an objectManager is in loads, that manager queries the master controller for references to every NPC currently using objects it manages, and spawns those NPCs appropriately.
This sounds okay, but a little shaky: is there a design pattern I’m missing here that would be a better fit for the task of tracking and spawning/despawning NPCs in a large world?