Creating Dynamic Actor Instances During a Playing Session

During a playing session, you can automatically create dynamic actor instances using JavaScript.

You can create dynamic instances for all actors (2D, 3D or logical).

When you create instances during a playing session, instances appear in red under their corresponding category in the Project panel. Once the playing session ends, dynamic instances disappear.

See Also
About Templates
  1. Create a script from the Behavior Editor.
    For more information, see Creating Scripts.
  2. Add your JavaScript code.
    beScript.onStart = function () {
    	var exp = STU.Experience.getCurrent();
    	var template = exp.getActorTemplateByName("SphereTemplate");
    	if (template !== null && template !== undefined){
    		for (var i = 0; i < 10; i++){
    			var options = {
    				name: "Test",
    				parent: null,
    				incrementName: true,
    				onInstantiationSuccess: function (iInstance) {
    					console.log("New instance " + iInstance.getName() + " created successfully");
    					var trans = new DSMath.Vector3D(i * 1000, 0, 0);
    					iInstance.translate(trans);
    				},
    				onFailure: function (iInstance) { console.log("Error during instantiation"); }
    			};
    			template.createDynamicInstance(options);
    		}
    	}else{
    		console.log("Error: template not found");
    	}
    };