microsoft / MixedReality-UXTools-Unreal

UX tools and components for developing Mixed Reality applications in UE4.
https://microsoft.github.io/MixedReality-UXTools-Unreal/
MIT License
316 stars 86 forks source link

Add Pointer Grab and Release event dispatcher #22

Closed crssnky closed 3 years ago

crssnky commented 3 years ago

I want to receive these events. We can focus objects because #20 . Next, I want to action to objects same time.

I wrote it. https://github.com/crssnky/MixedReality-UXTools-Unreal/commit/eaeb479a8d923e0eb6675e1de442b8d20e9dc29e

It works. (This account is my other account.) https://twitter.com/croMisa/status/1356262260654567425

luis-valverde-ms commented 3 years ago

Hey @crssnky , if I read it right your grab and release events are the same as far pressed and far released. You can instead derive from UxtTouchableVolumeComponent and override OnFarPressed_Implementation and OnFarReleased_Implementation. If you do so, remember to call the base class implementation from the method overrides!

crssnky commented 3 years ago

Currently, I want to receive a ReleaseEvent. Further, I want that it events at any time.

OnFarReleased_Implementation is called when FarPointer release in TouchableVolume. It does not receive ReleaseEvent when FarPointer is away.

luis-valverde-ms commented 3 years ago

Understood, you want global events. In that case, have a look at UUxtInputSubsystem::RegisterHandler. You can use it like this:

UCLASS()
class MyFarHandler : public IUxtFarHandler
{
    GENERATED_BODY()

    virtual void OnFarPressed_Implementation(UUxtFarPointerComponent* Pointer) override;
    virtual void OnFarReleased_Implementation(UUxtFarPointerComponent* Pointer) override;
};

MyFarHandler* Handler = ...;
UUxtInputSubsystem::RegisterHandler(Handler, UUxtFarHandler::StaticClass());
... 
UUxtInputSubsystem::UnregisterHandler(Handler, UUxtFarHandler::StaticClass());

Sorry for the lack of documentation around this, we're still working on it.

crssnky commented 3 years ago

Thank you for other suggestion.

Defining MyFarHandler. <- I understood.

Calling RegisterHandler. <- I can't understand. Where should I call it? I searched RegisterHandler in this plugin. I found it in only UUxtTapToPlaceComponent::StartPlacement. But, StartPlacement is called in OnFarReleased_Implementation...

Simply, I should call RegisterHandler in Initialize? (Maybe, GameMode class's constructor.)

luis-valverde-ms commented 3 years ago

I would call RegisterHandler/UnregisterHandler from the BeginPlay/EndPlay methods of the actor or component where you want to handle those events from.

You can make that actor/component inherit from IUxtFarHandler so you don't need to create a separate handler object. E.g.:

class AMyActor : public AActor, public IUxtFarHandler {}

If you want to handle the events from a blueprint you can just implement the IUxtFarHandler interface there directly. See https://docs.unrealengine.com/en-US/ProgrammingAndScripting/Blueprints/UserGuide/Types/Interface/UsingInterfaces/index.html

crssnky commented 3 years ago

I'm sorry I replied late.

I added the UInterface to my actor in Blueprint. But, my actor doesn not call release event.

I did not return true in "CanHandleFar" function. I return true, it works my wish!!

Thank you for your advice!!