question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prefab properties as setters and getters

See original GitHub issue

Currently 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:closed
  • Created 2 years ago
  • Comments:24 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
PhaserEditor2Dcommented, Jul 8, 2021
1reaction
PhaserEditor2Dcommented, Jul 7, 2021

Fixed the issue with the undefined declaration. This build also includes the prefab-awake event:

PhaserEditor2D-3.14.0-next-macos.zip

(You should disable the Networks cache the first time you open the editor)

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# setter/getters - Unity Answers
Hi I'm coming from a Java background. I cant find many resources on c# getters/setters in unity. I have prefabs with the Block...
Read more >
Using Getters and Setters in Unity - Stack Overflow
Properties allow you to fire events when values are set, for instance: An added bonus is that you can track when your property...
Read more >
Property getters and setters - The Modern JavaScript Tutorial
Accessor properties are represented by “getter” and “setter” methods. In an object literal they are denoted by get and set :.
Read more >
C# getters & setters - YouTube
C# getters and setters encapsulation tutorial example explained#C# # getters # setters // getters & setters = add security to fields by ...
Read more >
3. Properties vs. Getters and Setters | OOP - Python Courses eu
Getters (also known as 'accessors') and setters (aka. 'mutators') are used in many object oriented programming languages to ensure the principle ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found