Do you check in an Tick, this should allow you to respond properly to the sensor.
virtual void Tick(float DeltaTime) override
{
Super::Tick(DeltaTime);
EHMDWornState::Type WornState = UHeadMountedDisplayFunctionLibrary::GetHMDWornState();
if (WornState == EHMDWornState::Worn)
{
// HMD is being worn
}
else if (WornState == EHMDWornState::NotWorn)
{
// HMD is not being worn
}
else if (WornState == EHMDWornState::Unknown)
{
// HMD state is unknown
}
}
Other option is the subscribe to the event with the OculusSDK
OculusSDK::OnHMDWornStateChanged.AddUObject(this, &AYourActor::OnHMDWornStateChanged);
void AYourActor::OnHMDWornStateChanged(EHMDWornState::Type NewState)
{
if (NewState == EHMDWornState::Worn)
{
// HMD is being worn
}
else if (NewState == EHMDWornState::NotWorn)
{
// HMD is not being worn
}
}