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
4
Question by thaiscorpion · Nov 26, 2013 at 02:17 PM · javascriptalphamask

How to fade a game object will all its children?

I'm trying to use a fade effect for my menus and I want the whole menu to fade out, the menus is in a container. I tried iterating through the children of the container and changing the alpha value of the materials, but then as it fades you can see an overlap effect when there is more than one object on top of another.

Is there a way to fade a game object and its children together so I don't get the additive effect when there is more than one object?

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

3 Replies

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

Answer by Kiloblargh · Nov 26, 2013 at 08:54 PM

You just need a different shader, specifically one that writes to the depth buffer. Here is an example of that:

link

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 thaiscorpion · Nov 27, 2013 at 09:20 AM 0
Share

Thanks that works great, never really messed around with shaders :D

avatar image jmasinteATI · Aug 25, 2015 at 10:34 PM 0
Share

Has anyone gotten the shader linked (Specular VertexLit w Z) to work in the Animator/Animation system? I can fade it with a script, and even though it fades in the Inspector, it doesn't fade in the Scene or Game views.

avatar image
35

Answer by Ill-Fish · Aug 26, 2015 at 08:17 AM

with the new UI of Unity simply add a Canvas Group to the container and fade out the alpha of the Canvas Group. The children will also fade out with the parent object.

Comment
Add comment · Show 4 · 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 shaneparsons · Aug 04, 2016 at 03:10 PM 2
Share

This should be the accepted answer – it's the easiest method by far.

avatar image lunoland · Aug 04, 2016 at 03:14 PM 2
Share

Agreed, this is the most straight-forward "Unity" way to accomplish this.

avatar image jt7785 · Feb 07, 2021 at 09:29 AM 1
Share

This is the way to go. Thanks!

avatar image mfatihbarut · Jun 11, 2021 at 02:32 AM 0
Share

good one thanks.

avatar image
1

Answer by deltamish · Nov 26, 2013 at 06:41 PM

hi,

well there is pretty simple solution

 var FadeSpeed:flaot = 2;
 var Fade:boolean = false;
 function FadeAll(){
 
 for(var gb:GameObject in gameObject){
 gb.renderer.material.color = Mathf.Lerp(1,0,Time.deltaTime * FadeSpeed);
 }
 //Just in cae if the parent alpha hasnt changed
 gameObject.renderer.material.color = Mathf.Lerp(1,0,Time.deltaTime * FadeSpeed);
 }
 
 
 function Update(){
 if(Fade)
 {
 FadeAll();
 }
 }

Atttach this script to the parnet object and at runtime when you set Fade to true it will automaticall fade

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 gregroberts · Jan 04, 2015 at 03:40 AM 0
Share

that doesn't seem to work for me. I've amended the script:

     for (var _renderer : Renderer in gameObject.GetComponentsInChildren(Renderer) ) {
         if (_renderer) {
             for (var _material : $$anonymous$$aterial in _renderer.materials) {
                 var bC = _material.color;
                 _material.color = Color(bC.r, bC.g, bC.b, $$anonymous$$athf.Lerp (bC.a, 0.0, (Time.deltaTime * FadeSpeed)));
             }
         }
     }

still no joy...

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

25 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

Related Questions

Rewrite simple alphamask fixed function shader to surface or cg shader 2 Answers

Alpha mask to have a fading effect 2 Answers

Cut out sprite alpha using other textures 1 Answer

Cut out shader with geometry depth and alpha 0 Answers

Setting the alpha of an instantiated Canvas 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