TypeError: this.prefabEntity is undefined

Hi, I am trying to fetch Entity with below code in one js file. But I am getting error prefabEntity is undefined. Please help me on this. How we can fetch Entity’s reference in js.

//code
var Spawner = pc.createScript('spawner');
Spawner.attributes.add ('prefabEntity', {type: 'entity', title: 'Prefab'});

So this one showing undefined, when I am printing current object.

Hi @pankaj and welcome,

Have you referenced an entity in editor on that script attribute field?

The process when adding a field in a script usually involves:

  1. Adding the code in the script (much like you did)
  2. Parsing the script in editor
  3. Using the field to set its value

You can read more here:

https://developer.playcanvas.com/en/user-manual/scripting/script-attributes/

Hi Leonidas, Many Thanks for your support. Wow, this sorted my issue.

1 Like