![]() However, as you can see here, even though it says it's changed the transform in the blue line, the object itself wasn't taking effect (again).So, editing the GrandChild is still making trouble. I'm nearly there, I am now able to retrieve the correct transform values of the child as they are being displayed in the inspector : Also, I set the Canvas to Worldspace, before I had it "screenspace camera". I was now playing around, changed my code too and I'm now specifically searching for the child first, and changed the object to RectTransform. Sorry for spamming around here, but we all know that fighting through errors is the best way to learn anything, and I learned quite something since yesterday. Is it possible that this could be a bug ? I'm using Unity 2017.31f1 It works as supposed when I put the object in the main level, it even works great when it place the object as a child of a new gameobject, as long as it is not beneath the canvas, everything works. Using localPosition or just position has also no different effect. But now, when I try to change the position, even if starting by 0,0,0, the code returns me even a changed transform, but the object has not moved at all. No matter how often I redo or reset it, the coordinates in the editor always show up like in my image above. Even If I put the script direct on the low level group object, and then try to retrieve it's transform, I'm now getting 0,0,0 as a transform value (which is true for Canvas AND my test object) back, which seems to be ok for world coordinates. As long as I'm a child of the canvas, I am unable to manipulate the transform of the ChildObject. Made some test, the reason must be the canvas. Luckily the entire Unity UI codebase is open source on Bitbucket for your ultimate reference (Google) in case you get stuck on how something is calculated. It's pretty straightforward but there are some surprises in terms of what fields mean what, anchors, pivots, positions, sizes, etc. ![]() I'd recommend starting with a single Image GameObject under a Canvas, then take references to the RectTransforms in each and do some Debug.Log() printing to see what their values and relationships are. If you are trying to calculate and drive meaningful values in code for sub-objects, you will need to know the values in the RectTransform of the Canvas as well, as they are implicitly relative. This could be various coordinate systems based on the "Render Mode" setting field in that root Canvas object. RectTransform objects operate in the numeric context of the Canvas RectTransform under which they all live. Pretty sure there IS a way to get that to work, but when you are dealing with UI, you want to use only RectTransform objects in that hierarchy. You appear to be mixing Transform and RectTransform objects in a hierarchy. The logs show, the code is being executed, but it uses a wrong coordinate system. I need to move the MainMenuButtons-Object to the LOCAL coordinates that are displayed in the lower right (z-values can remain unchanged). In the Image you can see the canvas at 0,0,0, the Spawner_MainMenuButtons on it's own Transform, and then the MainMenuButtons (which has only a normal transform, and no Rect Transform for whatever reason). The logs show, my code actually works, but the math is wrong, I think it's calculating everything in world coordinates, and not the "local of the local of the worldspace" if you know what I mean.Ĭan someone please help me out here ? I goggled a lot and found, that there is something called "localPosition" for the child, but it's not working either. So, I want to use the script to move them in their hide position by changing their transform position and scale. I could totally avoid all this trouble if I just simply set the initial transform that way in the scene view, but I need these things visible in the scene view to work with them (at least for now), so I have to have them stay in normal size. but for a smooth animation, I need them to go in their invisible and microscaled start position (the spawners position). This group of buttons is animated, and when the scene first loads, I need to play the "load animation" (they start in the position of the "Spawner_MainMenuButtons" and then grow to the virtual screen that is seen in my canvas. I have a Grandchild (child of a child) object, named "MainMenuButtons", it's a empty gameobject that I used to group together some buttons. Please take a look at the enclosed image. I am fighting with Unity transforms, and at least for a beginner like me, it's a night mare since the objects all have "relative" coordinates instead of fixed ones (and most likely, I maybe didn't set up everything correctly). This might be a beginner question for most of you, but after a whole afternoon of googling, reading and trial & error I'm out of ideas.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |