Search Unity

Creating a "machine" in ECS?

Discussion in 'Scripting' started by Zymes, May 15, 2019.

  1. Zymes

    Zymes

    Joined:
    Feb 8, 2017
    Posts:
    118
    So I want to get started in ECS but have no idea how to set this up.

    I have a very simple example. If you ever played Minecraft or any other RPG where you insert an item into a block/machine and it outputs another item then you understand what I want to do.

    Let's use Minecraft as an example.

    In Minecraft we have a furnace, the furnace runs on coal. It can take a specific type of items as input and process them and produce an output. For example you could insert raw pork and it will output cooked pork.

    With MonoBehaviour I solved this using scriptable objects and created a recipe of allowed inputs and outputs. I had a gameobject that was my machine and it could hold another gameobject which was the input.

    Could scriptable objects be used with ECS?

    How would I use ECS to implement this machine that takes X and outputs Y and it will also calculate the duration of this process until it is complete.

    I assume I create a "System" that does the logic of processing this input item into its output? This system should probably also check if this input is valid.

    Should the "Component" define the machine as to what power source it uses? Should a component define the recipe list of items this machine can take as input?

    I am a little lost.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    There is no single way of doing things.

    You can hard code things, based on components and entities, or make more flexible, based on buffer / native arrays.
    Your machine could be entity, which has input and output buffers, storing items ids. System does own things. or instead buffer, item id, and current items count.
    Or have single array of machines, which refers to input and output array, of items and corresponding counts.
    Time can be per entity or preset.

    Really, no single universal solution.