Replies: 82 comments
-
If I strictly apply this model to Match One, I'd have to remove the How does this sound? Am I going crazy? :) |
Beta Was this translation helpful? Give feedback.
-
UI and Views visualize the current game state. They don't affect the game simulation. They can emit input like button clicks, but the game simulation doesn't know if this input came from a button, from the network or from some other program. That's why we don't need Entitas systems for them and can decouple them from the core logic as observers of the game state. UI and Views know how to represent the current game state. This allows us to start with placeholder assets which later can be replaced with the real game assets without touching the game logic. |
Beta Was this translation helpful? Give feedback.
-
We are doing it exactly like shown in the graphic. Furthermore we splitted the game logic into different parts: Action -> Command -> Core -> View. The View or other external inputs are able to create actions. The systems there are doing checks if it's possible and emit commands. The command systems will change the state of the core. Core systems only change core state. View is reacting on core and creating view state. Listeners are getting called, because something changed directly in core or in view. We also have a meta context which is just loaded balance values (from json just for easier access). This is done because action and view are part of unity (client side). Command and core are part of the simulation and will run not only on the client, but also on the server (we have a simulation game). |
Beta Was this translation helpful? Give feedback.
-
1st result of applying this strictly with TDD (Audio):
After:
Less complex and almost certainly more efficient I guess I'm going down this road further :) |
Beta Was this translation helpful? Give feedback.
-
Can you post your experiments into some repository? |
Beta Was this translation helpful? Give feedback.
-
i thinks it's good to use react system to tell ui & view logic. |
Beta Was this translation helpful? Give feedback.
-
Model looks nice and very intuitive, should be in wiki somewhere 😄 I wouldn't place |
Beta Was this translation helpful? Give feedback.
-
I also refactored my views now. All testable and very nice :)
|
Beta Was this translation helpful? Give feedback.
-
I really start loving the new events. It feels so clean now :) |
Beta Was this translation helpful? Give feedback.
-
Awesome. Btw @sschmid does it support loading some game objects first at loading time? For example, I want to load 10 enemies into game object pool first before starting game. I expect there is an API to preload the game object first into game object pool. |
Beta Was this translation helpful? Give feedback.
-
Updated diagram to include commands. Invalid input could be for example buying an item, but you don't have enough resources. Commands don't verify, they only act. |
Beta Was this translation helpful? Give feedback.
-
I recently built a few smaller games following the "Game Architecture with Entitas" diagram very strictly and I was really happy with the results. After the latest Video Tutorial about TDD #611 I started with strict testing again, and I have to tell you: |
Beta Was this translation helpful? Give feedback.
-
As another consequence I could get rid of the following contexts: Input, UI, Audio. I only have game and command context left. |
Beta Was this translation helpful? Give feedback.
-
ViewService, AudioService and all the other services are all less than 50 lines of code. Things became veeery simple now :) |
Beta Was this translation helpful? Give feedback.
-
@FNGgames What is your tag on UnityGameView for? |
Beta Was this translation helpful? Give feedback.
-
@cruiserkernan it's an enum tag i give to all entities - similar to unity's tag system, so i can find entities with tag or check a tag for something when i have a collision or whatever. It's just a component with an enum field. |
Beta Was this translation helpful? Give feedback.
-
That's exactly how I did before, too. If you think about, using the events, that's still exactly the same: a system will call a method that's implemented from an interface. The only difference is, these systems are now automatically generated and you don't have to write them + those systems work on all kinds of things, not only views. |
Beta Was this translation helpful? Give feedback.
-
@FNGgames Btw, thank you very much for your post. I love it :) Thanks for taking the time, I think it will help a lot of people who are new to all of this. |
Beta Was this translation helpful? Give feedback.
-
@sschmid good point RE: the events - there's still something talking to the views, but it's all hidden away. No problem on the article, tbh i probably wrote it all in chat a couple of times before - it's nice to just be able to give some a link now :). |
Beta Was this translation helpful? Give feedback.
-
To answer a question from the chat:
This is an optional idea that some of use to streamline adding new features and inputs.
|
Beta Was this translation helpful? Give feedback.
-
the larger the game and the more inputs you have, the more important it becomes to have a defined way how to handle those inputs. This approach helped me managing this even with lots of inputs |
Beta Was this translation helpful? Give feedback.
-
I just want to make sure if I understand it correctly. This would mean I have an Input, Command and Game context version of the components? Then, I have an InputSystem to filter the Input entity which creates a Command Entity, then have a CommandSystem to operate on the Command entity which it applies to the Game entity? |
Beta Was this translation helpful? Give feedback.
-
see comments above |
Beta Was this translation helpful? Give feedback.
-
Yes, that's the idea. Most of it can be generated as described in the comment above. So all I implement is just the execute of the input system and the command system. Everything else will be generated |
Beta Was this translation helpful? Give feedback.
-
@sschmid I wonder how you can like emits |
Beta Was this translation helpful? Give feedback.
-
What do you think about physics interaction with ECS/Entitas? If we need to interact with the physics, where would you put the "logic"? Here my example : I have a plane controlled by physics (Rigidbody.AddForce) and a PID controller to calculate the right amount of force to apply.
With various Entitas examples, I see that the views listen the position component to update its transform values, because it easy to see the position of the view as a state of the view. But with physics, like the velocity, is it a view state controlled by the rendering engine or is it part of the game logic and it could be unit tested? |
Beta Was this translation helpful? Give feedback.
-
@OmiCron07 I'd say it's up to the developer to decide. There is a balance what data to put into ECS layer and what to keep in View layer. I'd handle most of physics interaction inside View layer(or create FixedSystems to run in FixedUpdate). And occasionally send data through ECS components so that systems and eventSystems could react. |
Beta Was this translation helpful? Give feedback.
-
Sounds ok to create system to calculate something and another system to apply calculations.
It would work, could be tempting and easier to make but sounds more fragile in the long run.
Often
Physics changes unity transform values. It's possible to sync changes afterwards by checking |
Beta Was this translation helpful? Give feedback.
-
Thank you for the responses, will check it out how it turns out. |
Beta Was this translation helpful? Give feedback.
-
ECS Game Architecture with Unity and Entitas
This is my mental model based on which I decide where to put my code.
Feel free to comment so we can improve this model further
Beta Was this translation helpful? Give feedback.
All reactions