Search Unity

Should serialisable data be centralized or distributed?

Discussion in 'Scripting' started by Sendatsu_Yoshimitsu, Jun 17, 2018.

  1. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I'm working on an AI system in which every NPC has one or more Schemes, which are just semi-adaptive goals that they pursue independent of the player. A lot of the heavy lifting, like translating goals into a series of discrete actions that AI agents can execute, is done by individual schemes, so it's important that the AI manager can view and retrieve every active scheme based on its ID.

    I could do this by either giving each NPC some List<Scheme> of every scheme that they're involved in, or by giving the AI manager itself a single master list and storing the ID of the NPC that's executing each scheme inside of itself.

    Is there any obvious reason to favor one approach over the other? Centralizing them is going to add some search activity, since every time the AI updates I'll have to iterate through every scheme, locate a ref to the NPC it applies to, and invoke NPC.TickScheme(Scheme), but my intuition is that distributing the data across the NPC network will actually add more computation over time, since every time I need to iterate through schemes I'll have to make a new master list and merge every single NPC's data into it.
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    The centralized approach seems cleaner. It's also a setup that (probably) translates to ECS easier, if that's something you have on the horizon.

    The big downside with having the information centralized is that you have to do extra maintenance when creating, destroying, activating and deactivating NPCs. In the distributed scenario, where the NPCs just tick themselves in Update or whatnot, you can just create or destroy an NPC and be done.
     
  3. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I think we're thinking along the same lines here... one of the things that caused me to consider decentralized storage in the first place was that a lot of quests involve multiple NPCs running procedurally-generated schemes that left bread crumbs to the sidequest, and even basic tasks like advancing a scheme or iterating through each character's inventory and deleting key items when schemes/quests resolved themselves was a pain in the butt. Since there isn't an obvious reason to favor either approach though, I'm probably going to end up sticking with centralized storage if for no other reason than because it'll be much easier to go from centralized-decentralized if something changes in the future than it will vice-versa.