{"action":"created","issue":{"url":"https://api.github.com/repos/UPBGE/blender/issues/230","repository_url":"https://api.github.com/repos/UPBGE/blender","labels_url":"https://api.github.com/repos/UPBGE/blender/issues/230/labels{/name}","comments_url":"https://api.github.com/repos/UPBGE/blender/issues/230/comments","events_url":"https://api.github.com/repos/UPBGE/blender/issues/230/events","html_url":"https://github.com/UPBGE/blender/issues/230","id":179546148,"number":230,"title":"Implicit behavior of .setParent() method","user":{"login":"vlad1777d","id":12682937,"avatar_url":"https://avatars.githubusercontent.com/u/12682937?v=3","gravatar_id":"","url":"https://api.github.com/users/vlad1777d","html_url":"https://github.com/vlad1777d","followers_url":"https://api.github.com/users/vlad1777d/followers","following_url":"https://api.github.com/users/vlad1777d/following{/other_user}","gists_url":"https://api.github.com/users/vlad1777d/gists{/gist_id}","starred_url":"https://api.github.com/users/vlad1777d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vlad1777d/subscriptions","organizations_url":"https://api.github.com/users/vlad1777d/orgs","repos_url":"https://api.github.com/users/vlad1777d/repos","events_url":"https://api.github.com/users/vlad1777d/events{/privacy}","received_events_url":"https://api.github.com/users/vlad1777d/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-09-27T16:36:29Z","updated_at":"2016-09-27T19:25:15Z","closed_at":null,"body":"Hello dear friends.\r\n\r\nToday my friend appealed to me and said, that he wanted to change camera's parent, but it didn't work. \r\nAfter this he gave me the test scene. I found and implicit behavior in it, that may confuse not fluent with Python people.\r\n\r\nThere is an implicit behavior of .setParent method of KX_GameObject.\r\nExample scene: \r\n[Parent.blend.zip](https://github.com/UPBGE/blender/files/495811/Parent.blend.zip)\r\n\r\nHere we have \"Sphere\" on active layer; \"Cube\", \"Suzanne\" on hidden layer (\"Cube\" is parent of \"Suzanne\").\r\nPressing \"w\" we activate moving of \"Cube\" forward, \"s\" - backward; pressing \"space\" will activate function main() of parent.py. We launch file:\r\n![2016-09-27 18-04-50](https://cloud.githubusercontent.com/assets/12682937/18879433/f34607e8-84dc-11e6-8ef3-d25ef0d2859f.png)\r\n\r\nThen we press \"space\" and move appeared cube:\r\n![2016-09-27 18-07-28](https://cloud.githubusercontent.com/assets/12682937/18879525/465bad52-84dd-11e6-86bb-25767e0033a5.png)\r\nFrom terminal we see objects in scene: Sphere, Lamp, Camera, \\_\\_default\\_\\_cam\\_\\_, Cube, Suzanne;\r\nand \"Cube\"'s children: [Suzanne].\r\nSo \"Sphere\" does not became child of \"Cube\". \r\nIt's all right, because in API we can read that .setParent() needs a KX_GameObject as parent argument, but we gave it the name of object: \"Cube\".\r\n\r\nLet's press \"space\" another time and then move objects:\r\n![2016-09-27 18-13-14](https://cloud.githubusercontent.com/assets/12682937/18879760/2b27305a-84de-11e6-91c7-41c8ae7fab94.png)\r\nWe see, that another \"Cube\" and \"Suzanne\" were added successfully:\r\nObjects in scene: Sphere, Lamp, Camera, \\_\\_default\\_\\_cam\\_\\_, Cube, Suzanne, Cube, Suzanne, Sphere.\r\nCube's children: [Suzanne]\r\nBut there was added another instance of Sphere! **<< implicit behavior**\r\nAnd \"Cube\" does not became \"Sphere\"'s parent. **<< implicit behavior 2**\r\nThen when we added new instance of \"Cube\", new instance of \"Sphere\" was added too. But original \"Sphere\" does not got needed parent (it's parent still was \"Cube\" from hidden layer).\r\n\r\n**_Implicit behavior_**: \"Sphere\" got parent from hidden layer, after adding that object from hidden layer, automatically added all his children, including another instance of \"Sphere\".\r\n**_Implicit behavior 2_**: method .setParent() must receive only KX_GameObject, but it has worked with string - name of object, which made confusing and another object (object from hidden layer) was made as parent to \"Sphere\".\r\n\r\nAlso made confusing fact, that object from hidden layer could be parented; and those fact, that several instances of one object can have one name. \r\nAnd those fact, that there was added another instance of object (\"Sphere\"), that was not on hidden layer. \r\n(but it's not a bug, if there would not such confusing situation, behavior with adding instances of children objects (whose parents are on hidden layers), would be expected, I think that if after .addObjects() generally are adding all child objects, excluding ones that are on active layer will be more unexpected by users. Also such excluding may lead to that some complex objects will have not some of components.)\r\n\r\nIf we will repeat pressing \"space\", there will be just added new instances of \"Cube\", \"Suzanne\" and \"Sphere\". If we would give to .setParent() not string, but KX_GameObject, than all would be well.\r\n\r\n**Variants of expected behavior**:\r\n- 1. .setParent() will not apply string and returns an error.\r\n\r\nBenefits: \r\n\\> explicit behavior, we certainly know, which object will be parent of which.\r\nDisadvantages: \r\n\\> we need to receive KX_GameObject first, and this is extra efforts, extra amount of code; \r\n\\> flexibility and possibilities of method are reduced.\r\n\r\n- 2. .setParent() will apply strings - names of objects, this would be added into API wiki. But every instance must have different name - added suffixes \".inst001\" and etc.\r\n\r\nBenefits: \r\n\\> explicit behavior, we certainly know, which object will be parent of which; \r\n\\> there would not be objects with same name - uniqueness in namespace.\r\nDisadvantages:\r\n\\> extra efforts from developers to implement;\r\n\\> untested behavior may lead to confuses and errors.\r\n\r\n- 3. .setParent() will apply strings - names of objects, this would be added into API wiki. But it will not add to object parent from the hidden layers, only from active ones.\r\n\r\nBenefits: \r\n\\> more explicit behavior \r\n(if object is on hidden layer - it's excluded from game process, it cannot move, etc. There are not many matters parenting to object, which is in hidden layer (only if you're building a complex object in runtime and going to add new instances of complex object to scene));\r\nDisadvantages:\r\n\\> very rare could be such situations, when user will need make object from hidden layer parent to another one.\r\n\\> could be confusion on choosing object from several it's instances.\r\n\r\n- 4. **.setParent() will apply strings - names of objects, this would be added into API wiki. But at first it'll search through instances of objects that are in active layers, only if there were not such objects, it searches through objects in inactive layers. If second - it'll write warning to terminal.**\r\n\r\nBenefits: \r\n\\> more explicit behavior \r\nDisadvantages:\r\n\\> could be confusion on choosing object from several it's instances.\r\n\r\n\r\n**I suggest to implement 4 variant**, but to think and discuss making different names to all instances.\r\n\r\nCould be such situations, when you need choose certain object from several it's instances as parent to another object. If they'll have different names, you'll need to check theirs location or other properties to choose needed one.\r\n\r\nBest regards,\r\nVladislav."},"comment":{"url":"https://api.github.com/repos/UPBGE/blender/issues/comments/249971055","html_url":"https://github.com/UPBGE/blender/issues/230#issuecomment-249971055","issue_url":"https://api.github.com/repos/UPBGE/blender/issues/230","id":249971055,"user":{"login":"vlad1777d","id":12682937,"avatar_url":"https://avatars.githubusercontent.com/u/12682937?v=3","gravatar_id":"","url":"https://api.github.com/users/vlad1777d","html_url":"https://github.com/vlad1777d","followers_url":"https://api.github.com/users/vlad1777d/followers","following_url":"https://api.github.com/users/vlad1777d/following{/other_user}","gists_url":"https://api.github.com/users/vlad1777d/gists{/gist_id}","starred_url":"https://api.github.com/users/vlad1777d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vlad1777d/subscriptions","organizations_url":"https://api.github.com/users/vlad1777d/orgs","repos_url":"https://api.github.com/users/vlad1777d/repos","events_url":"https://api.github.com/users/vlad1777d/events{/privacy}","received_events_url":"https://api.github.com/users/vlad1777d/received_events","type":"User","site_admin":false},"created_at":"2016-09-27T19:25:15Z","updated_at":"2016-09-27T19:25:15Z","body":"@BluePrintRandom It's object with mesh - \"Cube\"."}}
{"actor":{"display_login":"vlad1777d"}}