babbleon Posted April 12, 2018 Share Posted April 12, 2018 Hello, Say I have ParentName > ChildName1 > ChildName2 > ChildName3, is there a quick way to have Babylon tell me the name of the ultimate parent, no matter which child I choose? I can get immediate parent using... scene.meshes[i].parent ... but I need to go right to the top. Cheers, Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 12, 2018 Share Posted April 12, 2018 a recursive function getLastParent(target){ if(target.parent.parent){ return getLastParent(target.parent); }else{ return target.parent } }; or something like that. Arte and babbleon 2 Quote Link to comment Share on other sites More sharing options...
babbleon Posted April 12, 2018 Author Share Posted April 12, 2018 Cheers buddy! This sorted it with a small tweak: function getLastParent(target) { if (typeof target.parent != 'undefined') { if (target.parent.parent) { return getLastParent(target.parent); } else { return target.parent.name; } } }; GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.