Vibration icon indicating copy to clipboard operation
Vibration copied to clipboard

EntryPointNotFoundException while in Unity Editor

Open Carlfiii opened this issue 1 year ago • 2 comments

Trying to call Vibration.VibrateIOS(ImpactFeedbackStyle.Medium) while inside the Unity Editor returns an error. It works fine once built to the device though. I'm running this on a Windows 10 computer, so perhaps I'm missing some native IOS stuff. Might just deny it if I'm in the Unity Editor, but wanted to post this just in case.

The line that's causing the error: ` #if UNITY_IOS

public static void VibrateIOS(ImpactFeedbackStyle style)
{
    _impactOccurred(style.ToString());
}

public static void VibrateIOS(NotificationFeedbackStyle style)
{
    _notificationOccurred(style.ToString());
}

public static void VibrateIOS_SelectionChanged()
{
    _selectionChanged();
}    

#endif `

Error: _EntryPointNotFoundException: impactOccurred assembly: type: member:(null) Vibration.VibrateIOS (ImpactFeedbackStyle style) (at Assets/Vibration/Vibration.cs:84) SingletonMaster.VibrateInput () (at Assets/Scripts/Singletons/SingletonMaster.cs:133) SingletonMaster.Vibrate (VibrationType t) (at Assets/Scripts/Singletons/SingletonMaster.cs:109) MainMenu.Vibrate (VibrationType t) (at Assets/Scripts/Management/MainMenu.cs:162) MainMenu.ToggleMenu (System.Int32 index) (at Assets/Scripts/Management/MainMenu.cs:118) UnityEngine.Events.InvokableCall1[T1].Invoke (T1 args0) (at <7b2a272e51214e2f91bbc4fb4f28eff8>:0) UnityEngine.Events.CachedInvokableCall1[T].Invoke (System.Object[] args) (at <7b2a272e51214e2f91bbc4fb4f28eff8>:0) UnityEngine.Events.UnityEvent.Invoke () (at <7b2a272e51214e2f91bbc4fb4f28eff8>:0) UnityEngine.UI.Button.Press () (at Library/PackageCache/[email protected]/Runtime/UI/Core/Button.cs:70) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/[email protected]/Runtime/UI/Core/Button.cs:114) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/[email protected]/Runtime/EventSystem/ExecuteEvents.cs:57) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/[email protected]/Runtime/EventSystem/ExecuteEvents.cs:272) UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/[email protected]/Runtime/EventSystem/EventSystem.cs:501)

Carlfiii avatar Mar 18 '23 14:03 Carlfiii

Try this

    public static void VibrateIOS(ImpactFeedbackStyle style)
    {
#if UNITY_IOS
        _impactOccurred(style.ToString());
#endif
    }

    public static void VibrateIOS(NotificationFeedbackStyle style)
    {
#if UNITY_IOS
        _notificationOccurred(style.ToString());
#endif
    }

    public static void VibrateIOS_SelectionChanged()
    
    {
#if UNITY_IOS
        _selectionChanged();
#endif
    }    ```

BenoitFreslon avatar Mar 19 '23 09:03 BenoitFreslon

Same error for me on Mac machine.

EntryPointNotFoundException: _impactOccurred
Vibration.VibrateIOS (ImpactFeedbackStyle style) (at Assets/Scripts/Vibration/Vibration.cs:85)

As I see, Vibration.cs already has those conditional ifs although it did not help:

    public static void VibrateIOS(ImpactFeedbackStyle style)
    {
#if UNITY_IOS
        _impactOccurred(style.ToString());
#endif
    }

I believe the issue is that unity editor is also considered UNITY_IOS. The solution is then to put #if !UNITY_EDITOR before the code invocation in the library. I went a bit further and added a Log when the vibration should happen in editor (just for testing) but it might be an overkill

#if UNITY_IOS
#if UNITY_EDITOR
        Debug.Log($"Impact with style {style} occured");
#else
        _impactOccurred(style.ToString());
#endif
#endif

Maybe it makes sense to create a wrapper around the Library that would encapsulate the logging part

static class MyVibration
{
    public static void Vibrate(ImpactFeedbackStyle style) // choose the name that fits you or just reuse the interface of the library
    {
#if UNITY_EDITOR
        Debug.Log($"Impact with style {style} occured");
#else
        Vibration.VibrateIOS(ImpactFeedbackStyle.Heavy);
        // Please note, Android is not handled, it's just an example
#endif
    }
}

dyrkabes avatar Apr 02 '23 09:04 dyrkabes