Forum Discussion

KevinJardine's avatar
KevinJardine
Start Partner
9 months ago
Solved

Disabling a trigger

Here's what I hope is an easy question. Once I hit a trigger, I want to deactivate it.
 
However, making it invisible does not deactivate it, and setting collidable to false
 
this.entity.collidable.set(false);
 
gives me an error message
 
"Unexpected error for action: setCollidability".
 
What am I doing wrong?
  • Hi there! I've done some experimentation, and I've found a solution to disabling a trigger after a player interacts with it. Here's a code example that should help:

    import { Component, TriggerGizmo, CodeBlockEvents, Player } from 'horizon/core';
    
    class DisableTriggerOnEnter extends Component<typeof DisableTriggerOnEnter> {
      start() {
        const triggerGizmo = this.entity.as(TriggerGizmo)!;
        if (triggerGizmo) {
          this.connectCodeBlockEvent(this.entity, CodeBlockEvents.OnPlayerEnterTrigger, (player: Player) => {
            console.log('Player entered trigger');
            triggerGizmo.enabled.set(false);
          });
        }
      }
    }
    
    Component.register(DisableTriggerOnEnter);

     This worked for me on my end, but I hope this helps with your issue, if you need any additional assistance, please let me know.

2 Replies

  • Hi there! I've done some experimentation, and I've found a solution to disabling a trigger after a player interacts with it. Here's a code example that should help:

    import { Component, TriggerGizmo, CodeBlockEvents, Player } from 'horizon/core';
    
    class DisableTriggerOnEnter extends Component<typeof DisableTriggerOnEnter> {
      start() {
        const triggerGizmo = this.entity.as(TriggerGizmo)!;
        if (triggerGizmo) {
          this.connectCodeBlockEvent(this.entity, CodeBlockEvents.OnPlayerEnterTrigger, (player: Player) => {
            console.log('Player entered trigger');
            triggerGizmo.enabled.set(false);
          });
        }
      }
    }
    
    Component.register(DisableTriggerOnEnter);

     This worked for me on my end, but I hope this helps with your issue, if you need any additional assistance, please let me know.

  • Thank you! Yes, that works for me. I had made two mistakes - forgetting to cast to TriggerGizmo and using collidable instead of enabled.