Entitas-csharp: Designing levels in the editor and Entitas

Created on 30 Jul 2015  路  10Comments  路  Source: sschmid/Entitas-CSharp

I saw you guy's UNITE talk and I'm so hyped for the framework. But I'm during the Q&A (48:27 into the talk) one person made a very valid point and that is the framework leaves the editor powerless. I saw your example project of cars and in the hierarchy there was game controller a camera and nothing else. One can't even change the position of the goal without changing code.

Since components are just data, isn't it possible to read data from anywhere? My idea is that maybe the code generator can generate placeholder MonoBehaviours. MonoBehaviours can be used by the designer to design. Then when the scene is run, add the placeholder entities to the pool with a start system that reads the data from the placeholder MonoBehaviour?

Thank you for making Entitas open source.

question

All 10 comments

I invite you to visit the Entitas chat, where we just had discussions about this very topic:
https://gitter.im/sschmid/Entitas-CSharp
Alternatively click the "Join the chat" button in the readme

You might want to scroll up until you see my reply saying "Designing levels"

Quote:

Designing levels

Let me explain, how I see this:
For me levels are just data - some configuration where things are and what their state is. E.g. a building at a certain position in the world that can be attacked and has a certain health.
I don't really care if I get this information from a json or a scene from Unity. In both cases I parse the source and create entities based on the data. In this example I'd create an Entity with BuildingComponent, PositionComponent, AttackableComponent, HealthComponent
The cool thing is, when you're designing your level in Unity, you already have the view, too! So when you parse your scene you already can link the actual building GameObject to the Entity by adding a ViewComponent

public class ViewComponent : IComponent {
    public GameObject gameObject;
}

Again: a designer is completely free to create a level. He/she can setup e.g. multiple buildings at different positions, with different health and so on... the important part is: All the Monobehaviours on that GameObject should NOT have any game related logic! Only configuration like transform, health, attackable, etc. They might have some View related logic like animating something on the building. The GameObject should be treated as a dumb view with no behaviour! It's just a View

I might create a third example project soon to illustrate what I just wrote, since this is a question that already came up a few times.

That would be amazing :smile: Thanks again! Really enjoyed the talk! Did a fantastic job selling what you guys have to offer to the audience. Instantly fell in love.

I'm one of the persons who had the same question as you. I've made something that works for me currently which essentially scans through the scene at start for any gameobject with a Component container-MonoBehaviour and creates entities using the components specified in the container. The container only has a list of IComponents that I can add and edit using VFW (https://github.com/vexe/VFW). This does not work during runtime though, then I have to go to the entity pool and edit those components, I'm still thinking about how to solve that (or just make it easy to jump to the correct entity during runtime). I'm also curious to see @sschmid solution =)

@mzaks wrote a blog post addressing this question:
Games, Data and Entitas

Here is an example which I think combines the best of both ECS and Unity world.
From the race car example add this to cars you drop into the scene:
using UnityEngine; public class OpponentInScene : MonoBehaviour { public float speed; }

Then change the InitOpponentSystem to this:
`using Entitas;
using UnityEngine;

public sealed class InitOpponentsSystem : IInitializeSystem {

readonly GameContext _context;

public InitOpponentsSystem(Contexts contexts) {
    _context = contexts.game;
}

public void Initialize() {
    // scan scene and register opponents which already exist
    var ops = GameObject.FindObjectsOfType<OpponentInScene>();
    foreach (var o in ops) {
        var e = _context.CreateEntity();

// e.AddAsset(resourceName);
e.AddView(o.gameObject);
e.AddPosition(o.transform.position.x, o.transform.position.y, o.transform.position.z);
e.AddMove(o.speed, o.speed);
}
//generate
const string resourceName = "Opponent";
for(int i = 1; i < 10; i++) {
var speed = Random.value * 0.02f;
var e = _context.CreateEntity();
e.AddAsset(resourceName);
e.AddPosition(i + i, 0, 0);
e.AddMove(speed, speed);
}
}
}
`

(sorry github ate my formatting, I'll figure it out eventually)

I think there's a project that tries to solve this very problem: https://github.com/WoLfulus/Entitas-CSharp-VisualEditor

@goshki Haven't had time to update it to the last version of entitas though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhuchun picture zhuchun  路  4Comments

LywOPUS picture LywOPUS  路  3Comments

jakovd picture jakovd  路  3Comments

moixxsyc picture moixxsyc  路  4Comments

angelotadres picture angelotadres  路  5Comments