• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Tomer-Barkan · Nov 16, 2013 at 07:47 PM · transformguitextureparenting

GUITexture set parent from script broken?

Wierd issue.

I have a large GUITexture used as background, with x,y = 0.3, 0.7, call it background.

I have another prefab, w$$anonymous$$ch is an empty GameObject, and wit$$anonymous$$n it a bunch of GUITexture and GUIText, call each one a gui entry.

In my script, I instantiate the background, then several of the gui entries. I mean them to appear one below each other, starting from the background. So I instantiate the background, then instantiate each gui entry with the background position + some offset, and it works fine.

But then I want to treat them all as one GameObject, so I try:

 guiEntry.transform.parent = background.transform;

Based on Transform.parent documentation: "Changing the parent will modify the parent-relative position, scale and rotation but keep the world space position, rotation and scale the same". In reality, what happens is that the world position of all the gui entries is reset to be that of the background. Moreover, after t$$anonymous$$s parenting, changing the localPosition of the gui entry does not$$anonymous$$ng, they still all appear one on top of each other. I tried changing the localPosition from code, and also from the Editor w$$anonymous$$le paused (I can see in the editor that they each have different position, and they all have the same parent, but in reality they appear on top of each other).

Any explanations?

I've recreated the following very simple scenario to demonstrate the problem. It always reproduces using unity 4.3, with any GUITexture including the default unity watermark:

 using UnityEngine;
 using System.Collections;
 
 public class test : MonoBehaviour {
     public Transform guiTexturePrefab;
 
     // Use t$$anonymous$$s for initialization
     void Start () {
         Transform parent = Instantiate(guiTexturePrefab) as Transform;
         Transform c$$anonymous$$ld = Instantiate(guiTexturePrefab, parent.position + new Vector3(0.1f, -0.1f, 0), Quaternion.identity) as Transform;
 
         // the following line breaks everyt$$anonymous$$ng
         c$$anonymous$$ld.parent = parent;
 
         // even if I add t$$anonymous$$s after parenting, they still appear on top of each other
         c$$anonymous$$ld.position = parent.position + new Vector3(0.1f, -0.1f, 0);
     }
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Nov 16, 2013 at 10:04 PM

T$$anonymous$$s issue does not require a script to recreate. In the editor, just make one GUITexture a c$$anonymous$$ld of another, and the c$$anonymous$$ld starts ignoring the 'position' values in the transform. I ran into t$$anonymous$$s a few weeks ago answering another question. I don't know if it is a bug in Unity or a limitation.

You can work around the issue by making the parent an empty game object, and then have both GUITexture game objects as c$$anonymous$$ldren. Give the one that you want to track the parent a position of (0,0,0), and then the c$$anonymous$$ld gets whatever relative offset you want...it looks like (0.1, -0.1, 0) for your code.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tomer-Barkan · Nov 16, 2013 at 10:16 PM 0
Share
avatar image robertbu · Nov 16, 2013 at 10:36 PM 0
Share
avatar image Tomer-Barkan · Nov 16, 2013 at 11:10 PM 0
Share

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Child object getting transformed out side the scene on collision? 1 Answer

Problem with multi touch[solved] 0 Answers

Network.Instantiate parenting on other clients 1 Answer

Why do Transform have hierarchies and not GameObjects? 2 Answers

NullReferenceException with SwitchController script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges