Script Attribute 'Entity' Array

Is there a way to designate a Script Attribute as Type ‘Entity’?

What about array of strings? Or array of numbers, etc.? Is that possible?

Array of Asset works fine but I can’t get an array of other items.

1 Like

Sorry, we don’t currently support either an Entity type or Array type for script attributes. They are on the roadmap though…

Has the ability to have entity attributes been fully integrated now? According to the doc the type of an attribute can be entity.

Yes, attribute type entity is now supported and lets you set a reference to an Entity in your script.

pc.script.attribute("myEntity", "entity" null);

update: function (dt) {
    // this.myEntity is a pc.Entity

OK because I am trying to use that and for some reason it does not work for me. The problem is that at some point when the engine is attempting to apply the entity attribute it enters an infinite loop and causes a Uncaught RangeError: Maximum call stack size exceeded at playcanvas-stable.js:30. I have been able to reproduce this error both with my engine only project and in a new project I created where I have 2 scripts: a tank.js and a test.js script. The test.js script is attached to a tester entity and creates a new entity and attaches the tank.js script to it which simply prints the name of the entity passed to the tank.js script as a ‘target’ attribute.

This is probably because you are assigning the Entity object to the attribute when you create the script component. Try using target.getGuid() instead of target.

            var tankScript = {
                name: 'tank',
                url: 'tank.js',
                attributes: [{
                    name: 'target',
                    value: target.getGuid()

I’ll bug this as we should handle assigning an Entity object instead of just the ID.

Awesome that did the trick, thanks :smiley:
Can you please add that bit about passing GUID’s rather than Objects to the API reference?