Use enum as attribute in different script


I was wondering if there was a way to define an enum in one script, and use it as the attribute in another?

So one script would have an enum defined and I want to have that same list of possible values as an attribute in other scripts.

Thanks for the help,

Yes, all attributes of a script are accessible by other scripts, just like normal properties.

// in script 1
ScriptOne.attributes.add('myEnum', { type: 'number', enum: [...] });

// in scsript 2

Ok, thanks for the response! Am I able to set the enum as an attribute in Script 2 though? So I can choose a value in the editor?

If you mean script 1 would show the enum of script 2 in the editor, then no, that is not possible.

Edit: the script 2 would have own enum, and you can add some code to sync the values between two enums. However, it doesn’t sound like a clean design. If your script 2 needs enum values of script 1, simply grab them, as I showed in the example, and keep only 1 enum visible in the Editor (in script 1).

Yeah I want to define the enum in script 1, but then have the drop down in the editor on the entity that has script 2 to select a value for that entity.

Each script file is parsed individually so the only way that you can do this is if you have both pc.Scripts in the same file.

Roger that. Thanks for the help guys!