Bug? - Inheriting attributes

I was playing around some more with script inheritance and encountered problems with attributes. I used the following script to test the following problems in an empty project.

1  var Test_Base = pc.createScript('test_Base');
2
3  Test_Base.attributes.add('dummy', { type: 'number', default: 10 });
4
5  Test_Base.prototype.initialize = function() { };
6
7  ////////////////////////////////   Child   ////////////////////////////////
8
9  var Test_Child = pc.createScript('test_Child');
10
11 // inheritance
12 Test_Child.prototype = Object.create(Test_Base.prototype);
13 Test_Child.prototype.constructor = Test_Child;
14
15 Test_Child.attributes.add('dummy', { type: 'number', default: 100 });
16
17 Test_Base.prototype.initialize = function() {
18     console.log(this.dummy);
19 };

Problem 1:
Attributes “seem” like they cannot be inherited, as they do not appear in the editor for child scripts. I need to define the same attribute for every child script (15), if I want them to expose the same attribute as their ancestor. Without it I can still access the dummy attribute with its default value. But as mentioned before the attribute is not exposed in the editor for Test_Child, so I can’t set the value outside of code.

Problem 2:
If I want to add attributes specific to the child script, their value is always undefined. If I comment out line 3 and break in line 18, I can see that the dummy attribute was added to the script, but it is undefined. So adding the attribute worked, but somehow somewhere, the value got lost/removed? I can only acces the dummy attribute’s value if I also add the attribute to the ancestor.
Contrary to Problem 1 though, the attribute still gets exposed in the editor, so it appears as if it could be set there.

Can someone help me out, explain to me what goes wrong here?
Thanks in advance

2 Likes

Script type inheritance isn’t right now supported by the editor/engine. I know that there was a hint by the Playcanvas team at some point for something like this but definitely isn’t there yet.

Not sure if you can trick the editor somehow to read your inherited object’s attributes correctly. If it is of any help here is the parse scripts worker to take a look on what it is looking for:

https://playcanvas.com/editor/scene/js/editor/assets/assets-script-parse-worker.js

@will and @vaios may be able to comment on this.