Prefab properties as setters and getters
See original GitHub issueCurrently in order to initialize a prefab property at init it is necessary to create an event handler per https://help.phasereditor2d.com/v3/scene-editor/prefab-user-properties.html#initializing-other-properties.
The downside to this approach is that it both requires an additional event handler to be setup, and if the property is changed later in code then the change won’t be reflected in the UI without the variable being checked periodically (e.g. in update).
To simplify the code and improve the usability, a getter and a setter should be created instead so the implementer can decide if a new variable is needed or if just a property on a Phaser object inside the prefab needs to be updated (e.g. the text on a button when updating the text property of the prefab).
So instead of
     this.scene.events.once(Phaser.Scenes.Events.UPDATE, this.start, this);
      // button (prefab fields)
      this.text = "Let's Go!";
     start() {
        this.textObject && (this.textObject.text = this.text)
    }
It can just be
    public set text(value: string) {
        /* START-USER-CODE */ 
        this.textObject && (this.textObject.text = value)
        /* END-USER-CODE */
    }
Issue Analytics
- State:
- Created 2 years ago
- Comments:24 (13 by maintainers)

 Top Related Medium Post
Top Related Medium Post Top Related StackOverflow Question
Top Related StackOverflow Question
Uploaded! PhaserEditor2D-3.14.0-next-macos.zip
Fixed the issue with the
undefineddeclaration. This build also includes theprefab-awakeevent:PhaserEditor2D-3.14.0-next-macos.zip
(You should disable the Networks cache the first time you open the editor)