{"action":"created","issue":{"url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/82","repository_url":"https://api.github.com/repos/sschmid/Entitas-CSharp","labels_url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/82/comments","events_url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/82/events","html_url":"https://github.com/sschmid/Entitas-CSharp/issues/82","id":139989264,"number":82,"title":"Proper way to restart a game?","user":{"login":"JamesMcMahon","id":916676,"avatar_url":"https://avatars.githubusercontent.com/u/916676?v=3","gravatar_id":"","url":"https://api.github.com/users/JamesMcMahon","html_url":"https://github.com/JamesMcMahon","followers_url":"https://api.github.com/users/JamesMcMahon/followers","following_url":"https://api.github.com/users/JamesMcMahon/following{/other_user}","gists_url":"https://api.github.com/users/JamesMcMahon/gists{/gist_id}","starred_url":"https://api.github.com/users/JamesMcMahon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JamesMcMahon/subscriptions","organizations_url":"https://api.github.com/users/JamesMcMahon/orgs","repos_url":"https://api.github.com/users/JamesMcMahon/repos","events_url":"https://api.github.com/users/JamesMcMahon/events{/privacy}","received_events_url":"https://api.github.com/users/JamesMcMahon/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sschmid/Entitas-CSharp/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2016-03-10T19:43:31Z","updated_at":"2016-03-10T22:26:33Z","closed_at":null,"body":"Hello again,\r\n\r\nAnother question for the Entitas team, what is the proper way to reset a game?\r\n\r\nTraditionally, when I want to reset a Unity application I manually reset any static state and reload the scene. In the cause of Entitas game, I need to be able to reset my pools and systems and get them back into the startup state. It appears that there are few helper methods for this, like `systems.DeactivateReactiveSystems()` and `pool.ClearGroups();`. But I haven't yet been able to figure out how to restart my game without the systems not coming back up correctly or groups behaving incorrectly.\r\n\r\nThis is what I am currently doing, I have a menu display on game over and then flip the Reset bool when a button is hit, then my GameController does the following;\r\n\r\n    void Update()\r\n    {\r\n        if (SharedState.Reset)\r\n        {\r\n            // remove all views\r\n            foreach (var e in pool.GetEntities(Matcher.View))\r\n            {\r\n                e.RemoveView();\r\n            }\r\n            // execute the systems once so the RemoveViewSystem can clean up game objects\r\n            systems.Execute();\r\n\r\n            systems.DeactivateReactiveSystems();\r\n            pool.ClearComponentPools();\r\n            pool.ClearGroups();\r\n            pool.DestroyAllEntities();\r\n            systems.ActivateReactiveSystems();\r\n            systems.Initialize();\r\n            SharedState.Reset = false;\r\n            return;\r\n        }\r\n\r\n        if (!SharedState.Pause && !pool.isGameOver)\r\n        {\r\n            systems.Execute();\r\n        }\r\n    }\r\n\r\nI then have issues with this following system pulling entities that are not falling (ie, not in this Matcher):\r\n\r\n    Group fallingGroup;\r\n\r\n    void ISetPool.SetPool(Pool pool)\r\n    {\r\n        fallingGroup = pool.GetGroup(Matcher.AllOf(Matcher.Position, Matcher.Falling));\r\n    }\r\n\r\n    void IExecuteSystem.Execute()\r\n    {\r\n        foreach (var e in fallingGroup.GetEntities())\r\n        {\r\n            // this is where the error happens, the entity doesn't have a falling component\r\n        }\r\n    }\r\n\r\nIf I disable this system I don't have explicit errors, but reactive systems don't appear to be working anymore. For example, my view objects are never recreated by my AddViewSystem.\r\n\r\nAny suggestions?\r\n\r\nIt would also be great to add an example of an Entitas restart to one of the example applications. Once again, I appreciate the help."},"comment":{"url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/comments/195079296","html_url":"https://github.com/sschmid/Entitas-CSharp/issues/82#issuecomment-195079296","issue_url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/82","id":195079296,"user":{"login":"sschmid","id":233700,"avatar_url":"https://avatars.githubusercontent.com/u/233700?v=3","gravatar_id":"","url":"https://api.github.com/users/sschmid","html_url":"https://github.com/sschmid","followers_url":"https://api.github.com/users/sschmid/followers","following_url":"https://api.github.com/users/sschmid/following{/other_user}","gists_url":"https://api.github.com/users/sschmid/gists{/gist_id}","starred_url":"https://api.github.com/users/sschmid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sschmid/subscriptions","organizations_url":"https://api.github.com/users/sschmid/orgs","repos_url":"https://api.github.com/users/sschmid/repos","events_url":"https://api.github.com/users/sschmid/events{/privacy}","received_events_url":"https://api.github.com/users/sschmid/received_events","type":"User","site_admin":false},"created_at":"2016-03-10T22:26:33Z","updated_at":"2016-03-10T22:26:33Z","body":"Basically it means, everywhere you use a group you now have to re-add your event handlers to the new group. The easiest solution would be to recreate all objects. I think it's easy to forget some place in your code where you stored a group in a field... not sure if one can handle this in a big project. Recreating all objects sound more bullet proof... But I'll take a look. Would be nice if Entitas itself can handle this"}}