Set entity of another script from my script

I have two instances of same script. I am trying to set entity of another script from my script. For example:

var Script1 = pc.createScript('script1');

Script1.attributes.add('currentObject', { type: 'entity' });
Script1.attributes.add('anotherEntity', { type: 'entity' });

// initialize code called once per entity
Script1.prototype.initialize = function() {
  this.anotherEntity.script.Script1.currentObject= this.currentObject; //this is not working

As you can see, I am trying to set the currentObject entity of the anotherEntity’s script. How do I do this?

You are close, just note the script type name isn’t Script1 but script1.

So do this instead:

this.anotherEntity.script.script1.currentObject= this.currentObject; //this is not working

Thanks that worked :slight_smile:

1 Like