Skip to content

Effects and sound

Compiles

Place the effect in the level, then tell it to play. Put an entity with an effect component next to your script’s entity, say a child named burst_fx. In the level editor, set the effect’s play_on_created off (so it waits for you) and kill_on_done on (so it stops when finished).

  • padtransformyour_script← your script
    • burst_fxtransformeffectplay_on_created off, kill_on_done on
fn play_burst() {
let fx: Entity = $entity.get_child_named("burst_fx", true, $entity.get())
if !fx {
return
}
let effect: Component = $support.entity_get_component(fx, "effect.vscript")
if effect {
$component.queue_event("play", effect, null, false)
}
}

effect also offers stop and kill.

✗ Crashes the game
// Fishing the effect asset out of another
// component and spawning it yourself.
let asset: Reference = effect.spawn_effect
$vfx.spawn_effect(asset, $entity.get(), "", false)
✓ Plays the effect
// Asking the effect component to play.
$component.queue_event("play", effect, null, false)

spawn_effect is a constant on effect, and constants can’t be read with a dot. The read gives nothing, and handing nothing to $vfx.spawn_effect crashes the game.

Only if the effect was made with a colour attribute. Many shipped effects bake their colour in, and asking to change it logs Invalid vfx attribute Color and does nothing. The effect component’s set_vec4_attribute event sets an attribute the effect does declare.

Sounds are sound events. Add a Reference setting for the event, pick it in the level editor, and post it on an entity:

// The sound to play; chosen in the level editor.
let chime: Reference = null
fn play_chime() {
if !chime {
return
}
$wwise.post_event($entity.get(), chime, false, 0, 0.0, 0, 0, false, false, 0.0, 0)
}

The sound plays from that entity’s position. The zeros and falses are the ordinary settings shipped scripts use; the wwise reference names each one.