Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Adding/Modifying proxy data after Instantiating converted Gameobjects

Discussion in 'Entity Component System' started by Enzi, Jun 11, 2019.

  1. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    954
    Hello!

    I think I have a conceptual problem. I've gone back and forth on the problem but I'm not finding good solutions.

    Let me describe the problem I'm handling:
    I have multiple building gameobjects that get converted from a buildingProxy with relevant data and a buffer that represent input and output of items. When the game is saved I write these values to the savegame, not the issue.

    But when loading, I load up a converted gameobject with a proxy. This proxy adds the input/output buffer but it can't initialize with any values. So, first question, where is the best place I should add the saved input/output values? Can I modify the proxy? Doesn't seem like a idea that works when batching.

    My spawner, which instantiates the converted gameobject already adds a SpawnComplete tag so I can post-process the new entity in case anything is missing.
    For example, before building I load up a preview object and on postprocess I save the entityId so I can directly delete it when a build command is canceled.
    In the SpawnComplete I also add the buildings to a hashTable for better lookups. Both processes stem from the problem that I don't know the entityId in advance. 1-2 post-processes aren't that bad just yet.

    But the more I add, the more I work around the proxy approach and come back to individual systems that handle a specific problem of data and it gets confusing and further away from building up a composite.

    Previously I had a 3 stage approach. Create entity with building data, step2 load the prefab and step3 tie them together, add to the hashtable and other stuff. But handling 2 entities that should be one was also a pain because of the TransformSystem and doing unneccesary copies from one entity ot the other so I tried the proxy approach which was working well until now.
    Maybe I should go back to something similar and write it without splitting it in 2 and only the spawned prefab gets the data turning into something like this:
    Load job with building and input/output data spawns the prefab and adds a component that adds CopyInput/output after the spawn.
    Goes against a composition too but it seems at least somewhat cleaner.

    Anyway, you surely found the need to persist data so how are you all handling this with the new workflow?