Enabled = false not actually hiding entity

Demo here: PlayCanvas | HTML5 Game Engine

I’m attempting to mark ‘muscular’ as enabled = false which should hide a big chunk of the model, but it’s visible.

Code is as follows:

var Hide = pc.createScript('hide');

// initialize code called once per entity
Hide.prototype.initialize = function() {
    this.entity.findByName("Muscular").enabled = false;

// update code called every frame
Hide.prototype.update = function(dt) {
    this.entity.findByName("Muscular").enabled = false;

// swap method called for script hot-reloading
// inherit your script state here
Hide.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/

It does find the entity and as you can see in the code I am doing a console log of the muscular entity which prints out that enabled is false…

for us to actually see the code better you should write //code then paste it

// code here
// movement
var x = 0;
var z = 0;

// Use W-A-S-D keys to move player
// Check for key presses
if (app.keyboard.isPressed(pc.KEY_A)) {
    x -= right.x;
    z -= right.z;

if (app.keyboard.isPressed(pc.KEY_D)) {
    x += right.x;
    z += right.z;

if (app.keyboard.isPressed(pc.KEY_W)) {
    x += forward.x;
    z += forward.z;

if (app.keyboard.isPressed(pc.KEY_S)) {
    x -= forward.x;
 z -= forward.z;

Hey @meds and welcome,

Is “Muscular” a child to the entity where you are applying the script? If not, try to find the entity like this:

this.app.root.findByName('Muscular').enabled = false;

If you keep having trouble, try posting a link to your project editor to take a look.

It definitely is a child, have verified this in unity and disabling that child does hide the muscles (in unity at least)

Here is the project, it’s a bit messy but the hide script is doing the work and it’s attached to the human model: https://playcanvas.com/editor/project/668737

It seems there isn’t an entity in your hierarchy named ‘Muscular’, so there is no way for the script to find it.

The name you put in this method


should be the same name that the entity has in the hierarchy, that you are trying to find.

But, I noticed that you’ve attached hide.js in the entity you’re trying to hide, so you can do this:

this.entity.enabled = false;

@Leonidas The ‘Musuclar’ graph node is in the mesh mode :slight_smile:

The ‘Musuclar’ graph node found doesn’t have a reference to the mesh instance so it doesn’t hide the mesh instance when disabled.

You would have to go through the list of mesh instances on the model component and find the mesh instance with a node with that name (yes it does sound backwards) and make it not visible via the API: https://developer.playcanvas.com/en/api/pc.MeshInstance.html#visible


Thank you for your help! I must admit I am a bit confused by your explanation but will go through your link and hopefully can work it out - I’m pretty sure there’s only one instance of Muscular but will double check.

Bit different to unity I guess hehe

Yeah, it’s a bit unintuitive and we are looking to improve this in the future.

If I get a bit of time, I will make an example project unless someone beats me to it.

Example project: https://playcanvas.com/editor/scene/987767

Musuclar doesn’t seem to exist as a mesh instance so I used a bicep instead.


That was really helpful! Does this mean setting enabled to false doesn’t effect children?

Not in the case of graphnodes that represents the transform of meshinstance unfortunately.

Ah yeah that is a bit annoying, still easy enough to work around. Would be good to get the full hierarchy working like how Unity3D does it but easy enough to work around.