Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Carrel · Mar 29, 2015 at 08:46 AM · iosinstantiaterecttransformanchor

UI changing position on instantiation on iOS

Hello fellow unityers! I have a problem with the positions of instantiated UI objects that only occurs when the project is compiled - I am using the new and wonderful Unity 5. I have a menu with a panel, with some elements inside (images and text) that are all positioned where i'd like with correct anchors, I use the following script to copy this panel, each time moving it to the right;

     public GameObject firstPannel;
     public int pannels = 10;
 
     void Start () {
         firstPannel.GetComponent<PlanetBoxConstructor>().construct(0);
         for(int i = 1; i<pannels; i++){
             GameObject newPannel = Instantiate(firstPannel, firstPannel.transform.position, firstPannel.transform.rotation) as GameObject;
 
             newPannel.transform.parent = transform;
             RectTransform rt = newPannel.GetComponent<RectTransform>();
             rt.sizeDelta = new Vector3(0,0);
             Vector3 newPos = newPannel.transform.position;
             newPos.x = firstPannel.transform.position.x*(i+1);
             newPannel.transform.position = newPos;
             newPannel.GetComponent<PlanetBoxConstructor>().construct(i);
         }

This works a charm in unity, and with other resolutions and screen sizes tried, but once compiled and put onto my iPhone5s all elements inside the copied panels are put into strange places. But are not this way in the original panel. The result:

alt text

I have tried making a script that resets the sizeDelta of each rectTransform to 0, one that sets all the anchor position to that of the element on the original but with no luck, here are my anchor positions, this picture is during runtime after the elements have been instantiated:

alt text

If anyone knows what I could be doing wrong I would be much appreciated :)

Thank you!

screen-shot-2015-03-28-at-153713.png (65.2 kB)
img-2303.png (256.2 kB)
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

Answer by Carrel · Mar 30, 2015 at 08:24 AM

Let me answer my own question, I've found how to fix it so i'm posting this for others with the same problem... I believe it could be a bug! The parent object of the original panel wasn't full screen size, which is what i wanted, the top anchors where about 20% down, and the bottom 20% up, left and right about 5% in, all this with the sizeDelta/position of the rectTransform at 0. When I changed the size of the rectTransform to take up the whole screen size, I no longer have this problem!

as it's only this way when compiled and not in unity I believe it must be a bug!

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Confused about game resolution settings for iOS 0 Answers

[SOLUTION] set UI RectTransform Anchor Presets from code c# 1 Answer

LineRenderer not instantiating on iOS or Xcode, Works fine in editor and Unity Remote 0 Answers

Trying to set RectTransform anchorposition in script 2 Answers

Anchor doesn't affect objects inside of another object 0 Answers


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