Entitas-csharp: EntitasPong Game's Open Questions

Created on 1 Aug 2016  路  12Comments  路  Source: sschmid/Entitas-CSharp

I am a game developer with 18 years experience. 4 years of full-time Unity experience with console (XBoxOne, PS4) and Mobile (iOS/Android).

Some of my various architectural approaches with Unity are documented here with examples. Entitas is not yet included there.

After seeing a Unite2016 presentation on Entitas, I decided to try it out. I have spent a few full days playing with Entitas and created a couple simple projects including EntitasPong/tree/0.1. Note: By design, that link is to Release0.1, not head.

For 0.1, I added "ENTITAS_HELP_REQUEST" in the code where I had questions. I'm not sure of the best way to share all those snippets in this post here, but all those snippets are compiled here. Note: That link is to head, not Release0.1. I don't know how to search a specific release :)

Please help :)

question

Most helpful comment

I also backported those changes to my EntitasTemplate project and then started a new 3rd project for fun :)

All 12 comments

Hey @srivello,

Entitas examples use x,y,z properties separately, but I use a Vector3. Best practices for Entitas?

I think that is totally up to you. I use Vector3 as well.

What does ensureComponents do? Is it only relevant to IReactiveSystems? Where is it documented online?

Systems operate in a deterministic chain:

``` c#
[System1] -> [System2] -> [System3]


Imagine System3 is a `IReactiveSystem` that reacts to "EventA". System1 produces EventA and System3 later does something... that's great. But what if System3 actually needs to some to get some data off the entity that System1 creates? Everything is fine _unless_ System2 removes that data before System3 can use it! `ensureComponents` makes sure that the entities that get passed to the system actually have the data you are looking for.

Another way to think about is reactive systems get triggered but don't execute immediately (they execute in the order they were added). Data can change from the time it got triggered to the time it actually executes. `ensureComponents` makes sure you only operate on entities with the components you actually asked for.

> What is the best way to address OPTIONAL components like Tick and Friction below?

There really is no concept of "optional components" but you can check for the existence of a component by using the methods on the `Entity` class that start with `has...`.

>  What areas of code do you recommend developers test?

Check out these tests:
- https://github.com/sschmid/Entitas-Shmup/tree/master/Assets/Tests/Editor

> What is a Feature? 

A feature is a special type of `Systems` that allows you to visually debug the systems in Unity.

> Features vs System?

A `Feature` is a collection of `System`'s.

> Where is this documented online?

I don't think it is and to be honest the name really confuses me :disappointed:. There are plans to update the wiki though! See #103

> What is the best practice to handle pausable vs unpausable systems?

I think the first step is modeling time explicitly with a system. Then it's just a matter of deactivating that system.

---

Also, I noticed this:

``` c#
public void SetPool(Pool pool) 
{
    // Get the group of entities that have a Move and position component
    _group = pool.GetGroup(Matcher.AllOf(Matcher.Velocity, Matcher.Position));
}

It's best practice to create your groups in Initialize() rather than SetPool() due to the way resetting pools works. Further discussion: https://github.com/sschmid/Entitas-CSharp/issues/82#issuecomment-195059578

Regarding pausing systems, check out this discussion: #120

Fantastic feedback, @mstrchrstphr. I'll wait a day in case anyone else comments here, then I'll commit code that addresses these issues and make a new 'Issue' with any remaining questions.

Hi @srivello, thanks for sharing and welcome to Entitas ;) I scanned through your code and here's my feedback

DestroyComponent

Since this class has no properties this attribute is required for it to be generated - srivello

Will also work without CustomPrefix. Default prefix is "is" (isDestroy)
Implementing IComponent is enough to be generated.

VelocityComponent

Entitas examples use x,y,z properties separately, but I use a Vector3. Best practices for Entitas?

Totally fine to use Vector3. Keep in mind that if you want to write your simulation logic totally independent from unity, it's good practice to write your own Point struct or just use x, y, z.

ViewSystem

What does ensureComponents do?

see https://github.com/sschmid/Entitas-CSharp/blob/master/Entitas/Entitas/Interfaces/IReactiveSystem.cs#L26-L32

Feature

What is a Feature?

Feature is basically the same as Systems. There is no difference other than it uses DebugSystems when playing in Editor (to get VisualDebugging) and normal Systems without the overhead in release builds.

VelocitySystem

What is the best way to address OPTIONAL components like Tick and Friction below?

Systems in general should not have any state (other than fields for optimizing performance, e.g. caching groups)
Optional components could be set to default value if not present in a IInitializeSystem

VelocitySystemTest
I recommend (and personally do so) writing test for all logical systems that are necessary for the core simulation.
The test looks great ;)
Get inspired here https://github.com/sschmid/Entitas-Shmup/blob/develop/Assets/Tests/Editor/describe_VelocitySystem.cs

@mstrchrstphr I should have read you answer first ;) Great answer, you totally got it :)

Thanks so much, @sschmid. I'll commit new code soon.

Here are all the areas mentioned above. I have completed fixes and committed EntitasPong/tree/0.2. and here is an update below. Thanks for all the help!

For Release0.2, I added "ENTITAS_HELP_REQUEST" in the code where I had questions. I'm not sure of the best way to share all those snippets in this post here, but all those snippets are compiled here. Note: That link is to head, not Release0.1. I don't know how to search a specific release :)

  1. Remove UnityEngine from all my Systems and Components.

    • I created RMC.Common.UnityEngineReplacement.Vector3 and a few others. This subject is a bit of a rabbit hole :) Probably such classes already exist in the community for a larger project

    • Exception: I do call CoroutineUtility.StartCoroutine(), which is dependent on UnityEngine, from within a few of my Systems. This is ok for now :)

    • Status: Done

  2. Update my use of 'ensureComponents'.

    • Removed all usages. Not needed (yet)

    • Status: Done

  3. Address answers to my Q: "What is the best way to address OPTIONAL components like Tick and Friction below?"

    • I simply added both Tick and Friction to the entity and remove the if's from the Execute()

    • Status: Done

  4. I like my approach to System Testing.

    • No changes needed.

    • Status: Done

  5. "Features vs System?" I'll keep my code as is. I already recommended it be added to the wiki on the wiki thread.

    • No changes needed.

    • Status: Done

  6. Per Pausing, I see some alternatives in other projects including GuardedSystems, but I like how I handle pausing.

    • No changes needed.

    • Status: Done

  7. It's best practice to create your groups in Initialize() rather than SetPool() due to the way resetting pools works.

    • I'll make that change soon.

    • Status: Done

  8. Remove attribute in DestroyComponent.cs and confirm class gets generated without it.

    • I confirm it does generate without it. Then I added it back because I prefer entity.WillDestroy(true).

    • Status: Done

I also backported those changes to my EntitasTemplate project and then started a new 3rd project for fun :)

Hi, I linked your pong project here
https://github.com/sschmid/Entitas-CSharp/wiki/Games-and-Examples
I hope that's fine with you

@sschmid That's great. For a more lean example for newbies, I recommend you also add this project I created if it meets your goals of that page.

https://github.com/RivelloMultimediaConsulting/EntitasTemplate

It clear almost all of my questions, indeed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

angelotadres picture angelotadres  路  5Comments

JamesMcMahon picture JamesMcMahon  路  5Comments

sschmid picture sschmid  路  4Comments

FiveP picture FiveP  路  3Comments

Noicon picture Noicon  路  4Comments