User properties in a prefab instance

This is how the properties you defined in a prefab are presented in the Prefab Instance section of a prefab instance:

User properties in a prefab instance.

The Inspector view shows a section for every prefab (and prefab variant) of the object. The user properties are shown just like any other property of a prefab instance.

Each section contains a menu with the options:

  • Open Prefab: opens the prefab file.

  • Select All <Prefab>: select all objects in the scene instancing the same prefab.

Prefab instance section and menu.

The code, generated by the scene compiler, that creates the prefab instance and initialize the properties will look like following. Note the dragon instance is created first, and the user properties are initialized later, at the end of the method. By setting the user properties at the end, it allows you to set references to another objects created in the scene:

class Level extends Phaser.Scene {
...
    create() {
        ...

        // dragon
        const dragon = new Dragon(this, 370, 218);
        this.add.existing(dragon);

        ...

        // dragon (prefab fields)
        dragon.maxSpeed = 300;
        dragon.flameType = "smoke";
        dragon.onClickHandler = obj => this.selectDragon();
        dragon.emit("prefab-awake");
        ...
    }
...
}

In the next sections are covered the topics to create prefab instances and to change the properties.