Document toolboxDocument toolbox

WIP 07 | Removing Actor Instances from a scene using a Destroyer

Goal: Learn how to destroy Actors in the simulation

Video Tutorial: https://www.youtube.com/watch?v=ZbMo1_6xzFQ

In the previous tutorial, we learned how to spawn Actors during the simulation with the help of a Blockable Spawner. But something that can be introduced into the simulation can also be removed from the simulation. This tutorial will explain how to destroy Actors from the scene.

The scene we are using is similar to the scene in tutorial ‘6 – Introducing new Actor Instances to a Scene using a Spawner', except that this time we have a new instructor called Destroyer and a second Cue at the end of the Spline, called DestroyCue. Whenever the center of an Actor intersects with this Cue, it will be removed from the simulation and destroyed.

ActorDestroyInstructor script

#if PRESPECTIVE_SOURCE || ALPHA using u040.prespective.prescripted.des.activities.motiontensor; using u040.prespective.prescripted.des.instructors; using u040.prespective.prescripted.des.participant.actor; using u040.prespective.prescripted.des.participant.cue; namespace u040.prespective.tutorials.desbasics { /// <summary> /// Demo script to show how an Instructor can destroy Actors that come into contact with a Cue /// </summary> public class ActorDestroyInstructor : DESInstructor { public override bool ApplyInstruction(ADESActor _actor, ADESCue _cue, ActorCueIntersectionEvent _intersectionEvent) { // We only want to destroy an Actor if it intersects with the destroy Cue with its center if (_intersectionEvent.IntersectionType != ActorCueIntersectionEvent.CueIntersectionType.Center) { return false; } // This is the only valid way of removing an Actor (or other simulation element) in DES // (Breaking events can require a destroyed Actor to be present, as such this method of removal will not immediately destroy the Actor // until the end of this frame, but for all intents and purposes it will no longer be part of the simulation after _intersectionEvent.EventTime SimulationController.RemoveParticipant(_actor, _intersectionEvent.EventTime); // Removing an Actor from the simulation is always a breaking event return true; } } } #endif

In the script, the center intersection event is used to trigger the method. The SimulationController then tries to remove the participant that is involved in the intersection event. Breaking events could require a destroyed Actor to be present. Therefor, this method of removal will not immediately destroy the Actor until the end of the frame, but for all intents and purposes it will no longer be part of the simulation after the intersection event occurred. Since an Actor is removed from the simulation, its is a breaking event and the method must return true.


Play Mode

When we press play, we see that we still have a 50-50% chance which Actor spawns. As soon as they reach the end of the Spline, they are removed from the scene. The Spawner only stops spawning when its area is blocked. Because spawned Actors are automatically destroyed, this does not happen anymore and the Spawner will continue spawning new Actors.

 

Prespective Documentation