playcanvas / playcanvas/engine

Enable then disabling a clone when cloned still shows the model

Open
#2,573 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: graphics
Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

Repo: https://playcanvas.com/project/739710/overview/disable-on-clone-initialise-bug
Press 1 to clone object.
Expected result: No box to be rendered

Taking into account of the clone code:

// update code called every frame
Main.prototype.update = function(dt) {    
    if (this.app.keyboard.wasPressed(pc.KEY_1)) {
        var e = this.entity.findByName('Parent');
        var c = e.clone();
        this.entity.addChild(c);
        c.setPosition(pc.math.random(-4, 4), pc.math.random(-4, 4), pc.math.random(-4, 4));
        c.enabled = true;
        c.enabled = false;
    }
};

The clone should not be visible.

Moving the code:

// initialize code called once per entity
DisableMeOnInit.prototype.initialize = function() {
    this.entity.enabled = false;
};

To postInitialize fixes the issues:

// initialize code called once per entity
DisableMeOnInit.prototype.postInitialize = function() {
    this.entity.enabled = false;
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the clone code and the entity initialize/postInitialize lifecycle shown in the issue. Reproduce the behavior by cloning the Parent entity, enabling it, and then disabling it; done means the cloned model is not rendered after being disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.