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 Anymeese · Aug 30, 2014 at 11:35 PM · uicanvas4.6healthbarhealth

(4.6 UI) Canvas position resetting itself to (0,0,0) when instantiating a new prefab with the canvas as child?

I have a unit prefab which has a canvas as a child. The canvas contains an image used as a health bar. The position of the canvas on the prefab is something like (0, 2.8, 0), and stays in position for units that I played in the scene BEFORE runtime, yet when I instantiate a new unit from the exact same prefab, the canvas is at (0,0,0). Why?

Comment
Add comment · Show 4
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 BMayne · Aug 31, 2014 at 04:22 AM 0
Share

Hey There,

Is your Unit under a parent canvas?

avatar image Anymeese · Aug 31, 2014 at 07:18 AM 0
Share

Nope! In fact, the only canvuses in the scene are the health bar canvuses (canvi?) for the two units

avatar image AleKahpwn · Sep 02, 2014 at 08:40 PM 0
Share

I am also having this issue, for some reason when you instantiate an object with a Canvas in world space it appears to reset the y value of it. I'm working on just having a script get the Canvas component and then re-position it after it's created, but if anyone comes up with an actual fix that'd be great.

avatar image Anymeese · Sep 02, 2014 at 09:49 PM 0
Share

While that would work, it doesnt change the fact that there is something else causing that to happen. Whether it be a bug since 4.6 is still in beta, or I'm doing something wrong, I'd like to know what the problem is and/or how to fix it! Otherwise I'll be scared something else will go wrong

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GluedBrain · Sep 01, 2014 at 06:41 AM

You got to set the slider anchors around the health bar slider, assuming you've used slider for your health bar. Setting the anchors in a correct manner will help you get rid of this issue.

THIS LINK

shows you how to create a Health bar using slider and set the anchor points of the slider. Hope this help!!

Comment
Add comment · Show 1 · 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 Anymeese · Sep 01, 2014 at 08:30 AM 0
Share

I didn't use a slider :( i used an image with the type set to Filler (horizontal). I already have the code working and everything, I just have the positioning issue

avatar image
0

Answer by jmack · Sep 06, 2014 at 10:29 PM

I had this same issue, like AleKahpwn said I have resorted to setting the Canvas component position via code:

 var canvas = gameObject.FindInChildren("Canvas");
 
             var canvasePos = canvas.GetComponent<RectTransform>();
             canvasePos.localPosition = new Vector3(0,8,0);
 
 
             var objectName = gameObject.FindInChildren("PlayerNameText");
             var playerName = objectName.GetComponent<Text>();
 
             playerName.text = "FINALLY";


 public static GameObject FindInChildren(this GameObject go, string name)
         {
             return (from x in go.GetComponentsInChildren<Transform>()
                      where x.gameObject.name == name
                      select x.gameObject).First();
         }
Comment
Add comment · Show 1 · 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 glowe · Oct 01, 2014 at 02:04 PM 0
Share

Agreed... same things happening to me. I position everything nicely, create a prefab, then on instantiate the positions of some elements in the canvas are in the center of the canvas, not where I placed them. I'm thinking repositioning in script is the only workaround. I wonder if this is just a beta bug...

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

27 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

Related Questions

Making a world-space UI look at all split-screen cameras? (split screen health bars) 0 Answers

How to get screen position of a RectTransform when canvas render mode set to "Screen Space - Overlay" 1 Answer

Unity 4.6 adding a Canvas Text onto a gameobject prefab?? -1 Answers

GUI in front of 4.6 UI 1 Answer

4.6 UI Image Color.Lerp 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