Fade multiple elements at once (especially disabled buttons)

hey everyone,

I started working on a UI today and wanted to fade in some objects I am creating during runtime from a base object which I copy and modify. The object consists of multiple elements: images, text, buttons.

I could not find a way to change the opacity for this group at one single point, but only fade their individual opacities. However fading a button which is active = false doesn’t do anything. Inactive Tint has alpha and overrides whatever you’ve set in opacity. :-//

The only solution I could think of is to attach more functions to the buttons and handle the color switch for active, hover, inactive and the not use the active bool on the button script but rather disable the component.
Seems like a lot of writing to me, not even complicated but just a lot of work.
Is there a better way to do this that I am not seeing? (lol maybe I’ll just render the main camera to an image before activating the 2d screen, push the render texture to a screen sized image and fade that one out instead xD)

aaaaaand well… wouldn’t it make sense to use opacity as a multiplier on whatever is set as colors in the button component … and just give the element color alpha too (because currently its only rgb)?

Not sure if it’s a bug or intended behaviour on this.

IIRC, having an element group type allows you to change the opacity of all the child elements via the group.

I made a new friend request widget before, where a widget would consist of image elements, text and accept/reject buttons. I animated the appearence of the main widget body, which is a simple image element, with a tween library. Tween library allows to act on transform completion events, so when one element is finsihed moving, I could start fading in or moving in another one. This effectively allows to chain animations of image elements. Fade ins / fade outs are done on the parent’s opacity, which affects all children inside the widget.

It was a while ago, so can’t remember exactly, but I think I slided the buttons out of the view, disabled them so they become hidden and then fade out the rest of the widget. Perhaps I could make an example.

sorry for taking so long to reply

since lexxik and yaustar both say it should work I am pretty sure I am not seeing something here. I would be glad for some pointers.

this is an example of the issue:
https://playcanvas.com/project/720264/overview/fademultipleelements

fadeTest.js animates an elements opacity using a tween from the initialize function.

  • It works on the “FadePerfectlyOnItsOwn” Image element
  • it works on the Image part of the Button “ButtonShouldFadeItsTextToo” but not for the child Text element part of the button (changing the image elements opacity doesn’t change the text’s opacity when doing it from the inspector either, but it should?)
  • it does entirely not work on the Element Group “ThisShouldFadeAllChildrenButDoesnt”. There is no error since the component obviously has the property but it is not exposed and children do not inherit it either.
  • fading does not work at all on inactive buttons because opacity is overwritten by the button component

Right, thank you @fleity for making a sample project.

So, as I remember how I did it before. As I mentioned, I slided the buttons under a full opacity image, and disabled them while they are hidden away from the view. Once hidden, I fade out the opacity of the image.

The buttons do not support a change of opacity. The only ones that do support are image and text elements. It is a valid request though, so I would recommend creating a github feature request. The closest you can get is probably changing the button transition mode from tint to sprite change and then fade the opacity of it.
image

The opacity not changing on children image and text elements is probably a bug, and I encourage you to make a github issue in the engine repo for it.

I use custom script for animate color/alpha on Image and second script for enable/disable entity. Second script listens event for animate script. Chain animation works. If needed - can share this two scripts. Supports image and text mode. They are required tween.js library.

Hello,

Running into this issue now, can’t find a property on the Group Elements which enable changing opacity for the whole group Group Elements | Learn PlayCanvas LayoutGroupComponent | PlayCanvas API Reference

Also creating an element of group type add with and height constraint which are not needed in this specific use case. Maybe creating a specific component I like the Canvas Group in Unity Canvas Group | Unity UI | 1.0.0

IIRC, there no setting, it just does it as default.

Edit, just realised you linked to layout groups.

The element component has a type of group
which is what I was referring to in my last post ElementComponent | PlayCanvas API Reference

Didn’t test via code, but the issue is Group in editor doesn’t provide an opacity value whereas Text/Image do.

Hmm… Doesn’t work via code either. I can’t remember how I’ve done it before now :thinking:

Coming back to PlayCanvas, running into the same issue several years later, and finding again this topic.

Is it somehow planned? Fading in or out several UI elements via the parent would be very convenient!