Enabling Script at runtime

Hello,

is there any way to access a script component in an entity for example “camera” and switch it on at a specific time at runtime

Thank you

Hi @abd_almajeed_saleh,

Yes definitely, it is so simply as enabling/disabling an entity. All components have an enabled property which can be used to set their enabled state.

For example in runtime:

// this will enable the script component of an entity called camera 
// the script component can hold more than one scripts
var cameraEntity = this.app.root.findByName("camera");
cameraEntity.script.enabled = true;

Now if you would like to enable/disable a certain script you will do it in a similar manner using the script’s name:

// this will enable only a certain script attached in the script component of the entity
var cameraEntity = this.app.root.findByName("camera");
cameraEntity.script.myScript.enabled = true;
1 Like