Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RomanLed · Dec 08, 2016 at 11:19 PM · mask

Changing rect of UI parent with mask component to reveal masked child object

It seems a simple functionality. I have an image child object utilizing the parent's mask component. During runtime, i could change the rect of the parent image to change the size of the mask to reveal more of the child's image, however this changes the child objects size too, so it doesn't really work without resizing the child images rect transform within code in the opposite direction. Is there a simpler way to accomplish this with just the UI components and coding the resizing of the parents size only?

EDIT: I guess within the code every time i adjust the parent's rect transform i could disable and re-enable the mask, though its incredibly un-optimized and ridiculous, especially when adjusting the size every update.

EDIT: It looks like in the 2D experimental preview theres sprite masking without parenting objects... hmm... whats the 2D experimental preview? lol

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 elenzil · Dec 09, 2016 at 12:23 AM

i could change the rect of the parent image to change the size of the mask to reveal more of the child's image, however this changes the child objects size too

this strongly suggests you haven't set up the RectTransform anchors & offsets the right way for what you want.

try making the min & max anchor positions all be [0.5, 0.5].

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 RomanLed · Dec 09, 2016 at 01:31 AM 0
Share

yea i guess your kinda right, ins$$anonymous$$d of anchoring in the middle, i could anchor the child image to one of the edges and then when scaling the parent from the opposite edge the child wont distort. It still doesn't work when scaling from multiple sides or moving the parent masks transform ins$$anonymous$$d just scaling. There was a movable, scalable sprite mask in the 2d preview build and then they replaced it with parent/child masks again. I dont understand why they don't just use a reference to a mask image/sprite ins$$anonymous$$d of needing a heirarchy. Oh well, for my purposes anchoring an edge works, thanks.

EDIT: Actually anchors don't really work, because when using an image ins$$anonymous$$d of a blank mask, no matter how its anchored, the image of the parent, and therefor the mask shape will change and distort. I think there isn't really a working solution because changing the transform will always change the shape of the mask. The only solution is to use no image and have a perfectly square mask, or to use the sprite reveal functionality Unity advertised and never implemented.

avatar image
0

Answer by Victory_Class · May 20 at 09:12 PM

I am trying to do a similar thing. I have my mask animated to reveal the child. But the child animates with the mask. Besides counter animating the child to the parent, I don't know any other way to fix this.

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

58 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

Related Questions

Masking with Mesh Renderer (2d) 1 Answer

Always on top mask shader? 2 Answers

Mask shader on Android devices 1 Answer

Combining partial Mecanim animations (using avatar masks) with ragdoll physics 2 Answers

Dynamically building sprite by using masks in unity 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