When Hit Target Change
Fires only when the object hit by the ray changes to a different one.
Introduction
When Hit Target Change is an event in the Ray Caster group of World Events. It fires only when the object hit by the ray changes to a different one, so it stays quiet while the ray keeps pointing at the same thing. Two details matter here. The object returned by this event is the root node, the outermost group, of whatever the ray actually detects. And switching from an object to nothing at all does not count as a change, so the event does not fire in that case. This event belongs to the Ray Detector component. Open the Ray Detector component guide to see everything the component itself can do. Ray casting is about aiming: this event fires whenever the ray finds a new target, which suits turrets, laser sights, and lock-on systems. Compare with the physical contact events When Colliding with Objects and the zone events When Trigger Entered , and read the Ray Caster component guide for range and layer settings. When Hit Target Change event in the World Editor Image The When Hit Target Change event in the Script Editor. caption
Parameters
Object the new object the ray is hitting Parameter Description
How to Access
How to Access - Event When Hit Target Change
How to Use
Select the object, press Propertie (the blue equalizer icon) in the bottom action menu, and scroll to the bottom of the properties panel. Press Add Component and pick the Ray Caster component; its block stacks below the existing properties with the When Hit Target Change event inside it. Press the + button below the event to add a script, then press Edit on that script to open the script editor and build the actions that should run when the event fires. Press Play and aim the ray at a different object, then check that the actions run.
Example
When hit target change by Object in Event: Set Object in Event, Character.Run Speed, Change To 1 when-hit-target-change-example.png Slows the newly hit character by setting its run speed to 1. caption
Common Uses
Slow down the character the laser just caught by setting its run speed Build laser puzzles that react to what the beam touches Switch turret behavior whenever it locks onto a new target
Tip
Because a change from object to nothing never fires this event, add separate detection logic if you also need to react when the ray stops hitting anything.