Making element interactive after addComponent

Ive been trying to add an element to an entity and have it be interactive however none of the interaction fire.

If i have an element already on the entity and just do the interactions it works fine.

    this.entity.addComponent('element', {
        type: 'image',
        anchor: [0.5,0.5,0.5,0.5],
        pivot: [0.5,0.5],
        spriteAsset: this.normal,
        width: this.width,
        height: this.height
    });
     
    this.entity.element.on('touchend', this.onRelease, this);
    this.entity.element.on('touchstart', this.onPress, this);

    this.entity.element.on('mouseenter', this.onEnter, this);
    this.entity.element.on('mousedown', this.onPress, this);
    this.entity.element.on('mouseup', this.onRelease, this);
    this.entity.element.on('mouseleave', this.onLeave, this);

Anyone know why this isnt working?

Check that useInput is true: https://developer.playcanvas.com/en/api/pc.ElementComponent.html#useInput

2 Likes