Skip to content

Commit

Permalink
Fix UIOpacity
Browse files Browse the repository at this point in the history
Fix the `node._objFlags & IsOnLoadCalled` logic.
  • Loading branch information
yoki0805 committed Aug 7, 2024
1 parent f59afb5 commit 1d51de1
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions cocos/2d/components/ui-opacity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
import { ccclass, disallowMultiple, editable, executeInEditMode, executionOrder, help, menu, serializable, tooltip } from 'cc.decorator';
import { EDITOR_NOT_IN_PREVIEW, JSB } from 'internal:constants';
import { Component } from '../../scene-graph/component';
import { CCObject, clamp } from '../../core';
import { clamp } from '../../core';
import { UIRenderer } from '../framework/ui-renderer';
import { Node } from '../../scene-graph';
import { NodeEventType } from '../../scene-graph/node-event';

const IsOnLoadCalled = CCObject.Flags.IsOnLoadCalled;

/**
* @en
* Set the UI transparency component.
Expand Down Expand Up @@ -138,12 +136,10 @@ export class UIOpacity extends Component {
return;
}

// If the node has never been loaded, then node._uiProps.uiComp won't be set.
// It has to be obtained by getComponent at this time.
let render = null as UIRenderer | null;
if (node._objFlags & IsOnLoadCalled) {
render = node._uiProps.uiComp as UIRenderer;
} else {
// If the node has never been actived, then node._uiProps.uiComp won't be set.
// We need to check if the UIRenderer exists or not.
let render = node._uiProps.uiComp as UIRenderer | null;
if (!render) {
render = node.getComponent(UIRenderer);
}

Expand Down

0 comments on commit 1d51de1

Please sign in to comment.