{"action":"opened","issue":{"url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/24","labels_url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/24/comments","events_url":"https://api.github.com/repos/sschmid/Entitas-CSharp/issues/24/events","html_url":"https://github.com/sschmid/Entitas-CSharp/issues/24","id":100441643,"number":24,"title":"Unity integration : GroupEventType.OnEntityRemoved is always fired even there is no Entity removed","user":{"login":"jraselin","id":13756640,"avatar_url":"https://avatars.githubusercontent.com/u/13756640?v=3","gravatar_id":"","url":"https://api.github.com/users/jraselin","html_url":"https://github.com/jraselin","followers_url":"https://api.github.com/users/jraselin/followers","following_url":"https://api.github.com/users/jraselin/following{/other_user}","gists_url":"https://api.github.com/users/jraselin/gists{/gist_id}","starred_url":"https://api.github.com/users/jraselin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jraselin/subscriptions","organizations_url":"https://api.github.com/users/jraselin/orgs","repos_url":"https://api.github.com/users/jraselin/repos","events_url":"https://api.github.com/users/jraselin/events{/privacy}","received_events_url":"https://api.github.com/users/jraselin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-12T00:37:55Z","updated_at":"2015-08-12T00:37:55Z","closed_at":null,"body":"Hi, \r\n\r\nBelow is the project configuration : \r\n* 2 components **Position** and **PlayerSelectActionAttack**\r\n* MonoBehaviour script **AttackPointerController** with 2 observers on **Matcher.AllOf(Matcher.PlayerSelectActionAttack, Matcher.Position)**\r\n* MonoBehaviour script **AttackController** to create / destroy the entity with the 2 components\r\n* Entitas System **PlayerSelectActionAttackSystem** with a group on **Matcher.AllOf(Matcher.PlayerSelectActionAttack, Matcher.Position)**\r\n\r\n**Position**\r\n```c#\r\npublic class PositionComponent : IComponent {\r\n      public float x;\r\n      public float y;\r\n}\r\n```\r\n**PlayerSelectActionAttack**\r\n```c#\r\npublic class PlayerSelectActionAttackComponent : IComponent {\r\n}\r\n```\r\n\r\n**AttackPointerController**\r\n```c#\r\npublic class AttackPointerController : MonoBehaviour {\r\n\tVector3 position;\r\n\tGroupObserver onAdded;\r\n\tGroupObserver onRemoved;\r\n\r\n\tvoid Awake () {\r\n\t\tPool pool = Pools.pool;\r\n\t\tGroup group = pool.GetGroup(Matcher.AllOf(Matcher.PlayerSelectActionAttack, Matcher.Position));\r\n\r\n\t\tonAdded = group.CreateObserver (GroupEventType.OnEntityAdded);\r\n\t\tonRemoved = group.CreateObserver (GroupEventType.OnEntityRemoved);\r\n\r\n\t\tposition = transform.position;\r\n\t}\r\n\r\n\tvoid Update(){\r\n\t\tforeach (Entity entity in onAdded.collectedEntities) {\r\n\r\n\t\t\tposition.x = entity.position.x;\r\n\t\t\tposition.y = entity.position.y;\r\n\t\t\tDebug.Log (\"Show Attack Pointer Position To \" + position);\r\n\t\t\ttransform.position = position;\r\n\t\t}\r\n\r\n\t\tforeach (Entity entity in onRemoved.collectedEntities) {\r\n\t\t\tDebug.Log (\"Hide Attack Pointer\");\r\n\t\t}\r\n\r\n\t}\r\n}\r\n```\r\n**AttackController**\r\n```c#\r\npublic class AttackController : MonoBehaviour {\r\n\tPool pool;\r\n\tEntity attackSelectedEntity;\r\n\tToggle toggleView;\r\n\r\n\r\n\tvoid Awake () {\r\n\t\ttoggleView = GetComponent<Toggle> ();\r\n\t\tpool = Pools.pool;\t\t\r\n\t}\r\n\r\n\tpublic void onAttackCheckedValueChanged(){\r\n\t\tif (toggleView.isOn && attackSelectedEntity == null) {\t\t\r\n\t\t\t\tattackSelectedEntity = pool.CreateEntity().IsPlayerSelectActionAttack(true).AddPosition(0,0);\t\t\r\n\t\t} else if(attackSelectedEntity != null){\r\n\t\t\tDebug.Log(\"Destroy entity\");\r\n\t\t\tpool.DestroyEntity(attackSelectedEntity);\r\n\t\t\tattackSelectedEntity = null;\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**PlayerSelectActionAttackSystem**\r\n```c#\r\npublic class PlayerSelectActionAttackSystem : IExecuteSystem , ISetPool {\r\n\tGroup _group;\r\n\t\r\n\tpublic void SetPool(Pool pool) {\r\n\t\t_group = pool.GetGroup(Matcher.AllOf(Matcher.PlayerSelectActionAttack, Matcher.Position));\r\n\t}\r\n\t\r\n\tpublic void Execute() {\r\n\t\tforeach (Entity entity in _group.GetEntities()) {\t\t\t\t\r\n\t\t\tVector3 point = Camera.main.ScreenToWorldPoint (Input.mousePosition);\r\n\t\t\tentity.ReplacePosition (point.x, point.y);\t\t\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n\r\n**Expected behaviours**\r\n\r\n1. User clicks on Attack button, **AttackController** is called ONCE and creates new Entity *pool.CreateEntity().IsPlayerSelectActionAttack(true).AddPosition(0,0);*\r\n2. **AttackPointerController** *onAdded* observer is updated with the created Entity and Console shows *Show Attack Pointer Position To [Entity.position]*\r\n3. **PlayerSelectActionAttackSystem** *_group* field is updated with the created Entity and entity position's is replace on each frame\r\n\r\n\r\n**Console Log**\r\n\r\n**AttackPointerController** *onRemoved.collectedEntities* must be empty but the console log shows :\r\n```\r\nShow Attack Pointer Position To (-1.3, -4.3, -4.1)\r\nHide Attack Pointer\r\nShow Attack Pointer Position To (-1.3, -4.3, -4.1)\r\nHide Attack Pointer\r\nShow Attack Pointer Position To (-1.3, -4.3, -4.1)\r\nHide Attack Pointer\r\nShow Attack Pointer Position To (-1.3, -4.3, -4.1)\r\nHide Attack Pointer\r\n...\r\n```\r\nIt seems like observers ignores the GroupEventType and populate *onRemoved = group.CreateObserver (GroupEventType.OnEntityRemoved);* with the newly created entity\r\n\r\n\r\n**Another issue**\r\n\r\nWhen the Entity created in **AttackController** is destroyed (*pool.DestroyEntity(attackSelectedEntity)*), there are an Exception on **AttackPointerController**\r\n```\r\nEntityDoesNotHaveComponentException: Cannot get component at index 11 from Entity_2()\r\nEntity does not have a component at index 11\r\nEntitas.Entity.GetComponent (Int32 index) (at Assets/Lib/Entitas/Entity.cs:87)\r\nEntitas.Entity.get_position () (at Assets/Sources/Generated/PositionComponentGeneratedExtension.cs:5)\r\nAttackPointerController.Update () (at Assets/Scripts/AttackPointerController.cs:25)\r\n```\r\n\r\nRegards"}}