Suggestion: a way to toggle editor visibility

Hi, I have elements that I want to be hidden by default, but I would like to see them in editor without having to toggle the checkbox everytime for each of them, because I have to hide them again every time I want to run the game.
Wouldn’t it be better if there was a different checkbox or something to toggle only editor visibility?
Am I the only one with this struggle?

Hello!
I solve this problem like this:


onLoad() { this.node.active = false; }

In this case, the value of the checkbox in the editor does not matter.

If you need to control visibility from the editor and you need a second checkbox for this, then you can simply do something like this:


@property(CCBoolean)
visible: boolean = false;

onLoad() { this.node.active = this.visible; }

ok i check

Can I have a visual code example please ??

I code with js

Hey i wanted the code example please

Above is almost all the code you need. I’m working with the latest versions of CC, so the code is in typescript. For javascript, I think it will not be very different, just throw away the type definitions. In general, the module will be like this:

import { CCBoolean, Component, _decorator } from "cc";
const { ccclass, property } = _decorator;

@ccclass("Visible")
export class Visible extends Component {

    @property(CCBoolean)
    visible: boolean = false;

    onLoad() { this.node.active = this.visible; }

}

Just add it to a node and mark whether the node should be displayed or not.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.