pankaj
August 11, 2021, 8:09am
#1
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:
Adding the code in the script (much like you did)
Parsing the script in editor
Using the field to set its value
You can read more here:
https://developer.playcanvas.com/en/user-manual/scripting/script-attributes/
pankaj
August 11, 2021, 9:00am
#3
Hi Leonidas, Many Thanks for your support. Wow, this sorted my issue.
1 Like