Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 MrWy07 · Aug 19, 2021 at 08:55 AM · uirenderingcanvasscreenspace

Can't position instantiated objects on canvas

I have a canvas set to screen space - camera. All works fine except for instantiated elements ( a 3d model and some rect transforms). When they are created, their position and size are completely different o.O. Any suggestions? It's working perfect with a world space canvas, but I find it more difficult to fit it to the screen..

screenshot-2021-08-19-115322.png (304.4 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

2 Replies

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

Answer by MrWy07 · Aug 19, 2021 at 11:40 AM

The idea is to create this objects dynamically based on some data, so I can't have them in the hierarchy before playing. Anyway, using transform.SetParent(transform, false) instead of transform.parent = gameTrans.transform does the trick, but I'll try your code and maybe see why this happens. Thank you!

Comment
Add comment · Show 2 · 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 GameDevMark · Aug 19, 2021 at 11:53 AM 0
Share

Ah I see! Can be frustrating sometimes, even the something as simple as changing a line can make the world of difference! Post again if you are still finding trouble, Good luck.

avatar image MrWy07 GameDevMark · Aug 19, 2021 at 11:54 AM 0
Share

I will, thank you!

avatar image
0

Answer by GameDevMark · Aug 19, 2021 at 10:02 AM

Check what scale size of the objects you are instantiating(prefabs). They instantiate to whatever size they are set to.

Let me know.

Comment
Add comment · Show 2 · 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 MrWy07 · Aug 19, 2021 at 10:42 AM 0
Share

Thanks for your answer, but the object I am instantiating is much smaller. It seems to work when I set a UI panel as parent using another method:

 chInstance = Instantiate(selectedCh.character, new Vector3(transform.position.x, transform.position.y / 2, transform.position.z), transform.rotation);
 chInstance.transform.Rotate(0, 180, 0);
 // chInstance.transform.parent = transform; 
 chInstance.transform.SetParent(transform, false);
 chInstance.transform.localPosition =  new Vector3(0, -chInstance.transform.parent.position.y / 2 , 0);
 chInstance.SetActive(true);
avatar image GameDevMark MrWy07 · Aug 19, 2021 at 11:34 AM 0
Share

Try changing transform.rotation for Quaternion.identity when instantiating. Just a maybe..

or maybe simplify it - just have the button or object disabled in hierarchy and then enable it in code? - SetActive(gameobject);

I've been messing around with instantiating buttons, texts, 3d objects onto the UI - Screen space, and it seems to work for me. I'll attach some code see if anything pops out for you, it is only simple code.

     void Start()
     {
         Button newButt = (Instantiate(buttonUI, transform) as GameObject).GetComponent<Button>();
         Text newText = (Instantiate(textUI, textTrans) as Text).GetComponent<Text>();
     }

     // spawn triangle
     void SpawnIT(int gridSizeee = 4)
     {
         for (int y = 0; y < gridSizeee; y++)
         {
             for (int x = y; x < 2 * gridSizeee - y - 1; x++)
             {
                 Vector3 pos = new Vector3(x, y, 0f);
                 var ballTri = Instantiate(balls, pos, Quaternion.identity);
                 ballTri.transform.parent = gameTrans.transform;
                 Debug.Log(balls);
             }
         }
     }

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

233 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 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 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 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 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 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 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 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 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 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 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 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 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 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

3D Objects on a UI canvas with LWRP? 2 Answers

GUI in front of 4.6 UI 1 Answer

Particle System not showing over "Screen Space - Overlay" UI Canvas 0 Answers

Use custom render pass to render world space UI without post processing 0 Answers

Strange Canvas behaviour at Screen Space - Camera mode? 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