Hi Forum,
it’d be interested in our thoughts about a general software design problem I have with Unity:
Background My background is in machine learning and AI, and I’d like to try Unity for Demos or Visualisations of experiments. However, many decision making algorithms (e.g. Monte Carlo Tree Search, Min Max) in multi-agent simulations rely on so called Game Trees, i.e. a projection of hypothetical game states based on potential actions of an agent, which then can be used to determine the agent’s next action.
I’m currently implementing a simple task planning algorithm that determines the sequence of actions an agent has to take to achieve a certain goal. It basically spans out all possible actions, looks what the resulting effects might be, how close the goal state is, what the possible actions then are etc. etc. However, the decision making algorithm isn’t really my topic here.
Problem Now, my problem is to find an efficient way to represent possible future game states. I figured that just cloning the Unity Scene graph doesn’t do the trick because each time I clone (Instantiate) a GameObject, its adjacent resources (e.g. mesh filter) are cloned as well. So I encapsulated my relevant game data as an object inside a MonoBehaviour script. Then, my agent’s decider queries all objects in a scene for this MonoBehaviour, grabs the data object inside and uses that for building the game tree (the data object implements IClonable). Of course, I have to clone and maintain the relations between the objects as well if necessary. For example, if my agent has to reach a coffee cup on a table, it has to move to the table in a hypothetical state so that it can discover that it has to move in order to reach the cup. But the hypothetical future table has to have a link to a hypothetical future coffee cup or this won’t happen. I hope that explains the idea a bit.
However, what this basically does, is building a parallel scene graph and I end up re-implementing something Unity already does.
So my question would be if anyone could think of a more efficient pattern, or has already tried that?