Search Unity

Is this a reliable way to mutate world state?

Discussion in 'Scripting' started by Sendatsu_Yoshimitsu, Feb 16, 2018.

  1. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I'm working on an RPG, and I need to give quests and story progression the ability to make temporary changes to game state, like altering where characters appear, what dialogue a given NPC plays, and causing quest items to spawn or despawn from a specific scene.

    The best way I've thought to do this is by thinking in terms of Overrides: every scene is spawned empty, and once it's loaded it has a SceneManager class whose job it is to find the database and ask for a list of characters/items/whatever else to spawn inside of itself. The database has a default list, which is hand-made by the developers, and a list of active quests/story content. When asked to return all of the spawnable stuff a given SceneID is associated with, the database makes two checks: first it looks at its default settings and returns everything that should normally appear, then it checks every quest's data class and asks it if it has any active spawn overrides. These can be positive (Neil the Knight should now spawn by the windmill) or negative (the knight who usually spawns by the windmill shouldn't be there), and the same logic applies to characters, items/treasures, and any other content that needs to be instantiated into the level.

    Consequently, all my quest/story editing tools need to do is keep track of which node/state of each quest is currently active, and let me attach spawn overrides to every node. This sounds pretty clean and hard to mess up, but I've never worked on an RPG before so I'm literally making the workflow up as I build it; does this seem like a fairly reasonable implementation, or is there a much cleaner solution that experienced studios stand by?