# Pointer.Pressed.AddHandler doesn't work inside Scene

**URL:** <https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392>\
**Category:** Bug Reports\
**Created:** [June 10, 2016, 8:54am UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392 "2016-06-10T08:54:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simo\_Santavirta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/simo_santavirta/32/175_2.png) [@Simo\_Santavirta](https://forums.fusetools.com/u/Simo_Santavirta)\
**Post date:** [June 10, 2016, 8:54am UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392/1 "2016-06-10T08:54:33Z")

</div>

```auto
Fuse.Input.Pointer.Pressed.AddHandler(Parent, OnPointerPressed);

```

Doesn’t work if CustomComponent if it’s inside a Scene.

```auto
<App>

    <Panel>

        <Scene Camera="CameraEntity">

            <Entity ux:Name="CameraEntity">
                <Frustum FovDegrees="120" ZNear="10" ZFar="10000" ux:Name="_CameraFrustum" />
                <Transform3D Position="0, 0, 0" RotationDegrees="0, 0, 0" Scaling="1, 1, 1" ux:Name="_CameraTransform" />
            </Entity>

            <CustomComponent ux:Name="MyCustomComponent" />

        </Scene>

        <Panel HitTestMode="LocalBounds" />

    </Panel>

</App>

```

Only way I got those touch events inside my CustomComponent was with:

```auto
<App>
    <JavaScript>

        module.exports.VisualPointerPressed = function(args)
        {
            MyCustomComponent.PointerPressed(args.x, args.y, args.index);
        }

        module.exports.VisualPointerReleased = function(args)
        {
            MyCustomComponent.PointerReleased(args.x, args.y, args.index);
        }

        module.exports.VisualPointerMoved = function(args)
        {
            MyCustomComponent.PointerMoved(args.x, args.y, args.index);
        }

        module.exports.VisualPointerWheelMoved = function(args)
        {
            //Can't get Wheel delta with this thing at all
        }

    </JavaScript>

    <Panel>

        <Scene Camera="CameraEntity">

            <Entity ux:Name="CameraEntity">
                <Frustum FovDegrees="120" ZNear="10" ZFar="10000" ux:Name="_CameraFrustum" />
                <Transform3D Position="0, 0, 0" RotationDegrees="0, 0, 0" Scaling="1, 1, 1" ux:Name="_CameraTransform" />
            </Entity>

            <CustomComponent ux:Name="MyCustomComponent" />

        </Scene>

        <Panel HitTestMode="LocalBounds" Pointer.Pressed="{VisualPointerPressed}" Pointer.Moved="{VisualPointerMoved}" Pointer.Released="{VisualPointerReleased}" Pointer.WheelMoved="{VisualPointerWheelMoved}"> 
            </Panel>

    </Panel>

</App>

```

And then Fuse.Scripting.ScriptClass.Register methods. Which feels like way too much work for getting a pointer events.

---

<div class="post-metadata">

**Author:** ![Vegard\_Strand\_Lende](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/vegard_strand_lende/32/349_2.png) [@Vegard\_Strand\_Lende](https://forums.fusetools.com/u/Vegard_Strand_Lende)\
**Post date:** [June 13, 2016, 1:32pm UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392/2 "2016-06-13T13:32:33Z")

</div>

Thanks for reporting!

I have raised an issue for this. Will keep this thread updated

---

<div class="post-metadata">

**Author:** ![Simo\_Santavirta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/simo_santavirta/32/175_2.png) [@Simo\_Santavirta](https://forums.fusetools.com/u/Simo_Santavirta)\
**Post date:** [June 27, 2016, 7:24am UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392/3 "2016-06-27T07:24:56Z")

</div>

I’m on osx 0.21.0(6650) and cannot get pointer events to my custom RenderNode.

I think this should work in a way that I can add handler to Pointer at OnRooted method inside my Custom RenderNode.

```auto
override protected void OnRooted()
{
    Fuse.Input.Pointer.Pressed.AddHandler(Parent, OnPointerPressed);
}

```

But it doesn’t.

Here’s a test case for you:

[http://www.simppa.fi/fuse/TestPointer021.zip](http://www.simppa.fi/fuse/TestPointer021.zip)

---

<div class="post-metadata">

**Author:** ![Simo\_Santavirta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/simo_santavirta/32/175_2.png) [@Simo\_Santavirta](https://forums.fusetools.com/u/Simo_Santavirta)\
**Post date:** [June 27, 2016, 7:31am UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392/4 "2016-06-27T07:31:45Z")

</div>

Also would like to add that the complicated way (explained in first post) of doing it doesn’t work either.

---

<div class="post-metadata">

**Author:** ![Simo\_Santavirta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/simo_santavirta/32/175_2.png) [@Simo\_Santavirta](https://forums.fusetools.com/u/Simo_Santavirta)\
**Post date:** [June 30, 2016, 6:50am UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392/5 "2016-06-30T06:50:11Z")

</div>

Would be really nice if this would not get forgotten, since it’s keeping me in a version 0.20.3, where Pointer work at least somehow on Android. (Not on iOS)

---

<div class="post-metadata">

**Author:** ![edA-qa\_mort-ora-y](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/eda-qa_mort-ora-y/32/124_2.png) [@edA-qa\_mort-ora-y](https://forums.fusetools.com/u/edA-qa_mort-ora-y)\
**Post date:** [July 1, 2016, 9:14am UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392/6 "2016-07-01T09:14:03Z")

</div>

I’ve recently done several fixes on viewports, which includes hit testing on scenes. It should work, as I think I only fixed a problem with MeshRenderer and non-fullscreen Scenes.

Pointer events are dependent on the hit testing of your component. You need to implement `OnHitTest` as well as `HitTestLocalBounds`, otherwise you won’t get any pointer events.

If you want to test the bounds quickly you can return `VisualBounds.Infinite`, which means you don’t know what the bounds. This will result in `OnHitTest` being called for all your objects on each pointer even though (it loses the optimization for hittesting).

---

<div class="post-metadata">

**Author:** ![Simo\_Santavirta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/simo_santavirta/32/175_2.png) [@Simo\_Santavirta](https://forums.fusetools.com/u/Simo_Santavirta)\
**Post date:** [July 1, 2016, 9:47am UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392/7 "2016-07-01T09:47:39Z")

</div>

Ok so I need to implement that in my uno code, right?

Can you please paste me the code.

---

<div class="post-metadata">

**Author:** ![Simo\_Santavirta](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/simo_santavirta/32/175_2.png) [@Simo\_Santavirta](https://forums.fusetools.com/u/Simo_Santavirta)\
**Post date:** [July 1, 2016, 10:14am UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392/8 "2016-07-01T10:14:30Z")

</div>

Ah starting to get somewhere with

```auto
protected override void OnHitTest(HitTestContext args)
{
    args.Hit(this);
}

protected override VisualBounds HitTestLocalBounds
{
    get { return VisualBounds.Infinite; }
}

```

---

<div class="post-metadata">

**Author:** ![edA-qa\_mort-ora-y](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/eda-qa_mort-ora-y/32/124_2.png) [@edA-qa\_mort-ora-y](https://forums.fusetools.com/u/edA-qa_mort-ora-y)\
**Post date:** [July 1, 2016, 11:23am UTC](https://forums.fusetools.com/t/pointer-pressed-addhandler-doesnt-work-inside-scene/1392/9 "2016-07-01T11:23:59Z")

</div>

Yes, that basic code will register a hit always. You’ll need to start figuring out whether you actually hit your object or not now.

Here’s a simple 3D visual that can detect hits on itself (a cube). It uses infinite bounds as a test as well.

```auto
public class MyObject : Visual
{
    float3 _color = float3(0.5f);
    public float3 Color
    {
        get { return _color; }
        set 
        { 
            _color = value;
            InvalidateVisual();
        }
    }

    public override void Draw(Fuse.DrawContext dc)
    {
        draw DefaultShading, Cube
        {
            World: WorldTransform;
            DrawContext: dc;
            Size: 1;
            DiffuseColor: _color;
        };
    }

    protected override void OnHitTest(HitTestContext args)
    {
        var ray = args.WorldRay;
        var box = new Box(float3(-0.5f),float3(0.5f));
        box = Box.Transform(box,WorldTransform);

        float distance = 0;
        if (Collision.RayIntersectsBox(ray, box, out distance))
            args.Hit(this);
    }

    protected override VisualBounds HitTestLocalBounds
    {
        //use infinite bounds for 3D space as in general trying to calculate 2D scene bounds is quite challenging
        get { return VisualBounds.Infinite; }
    }
}

```
