Gather Delegate Bug On IOS

Forums 💬 NodeCanvas ⚙️ Support Gather Delegate Bug On IOS

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18886
    tsingsan
    Participant

      If this is a known issue, please ignore it.

      I’m using NC 2.3.8, and the method “OnStateEnter” that I implement in my own Monobehaviour is not invoked at all on IOS.

      The function GatherDelegates looks like below for IOS platform.

      foreach (var mono in agent.gameObject.GetComponents<MonoBehaviour>())

      {

      ……

      CallbackEnter += (s)=>{ enterMethod.Invoke(mono, new object[]{s}); };

      }

       

      I found that all generated anonymous delegates are referring to the same captured variable, so the delegates would always try to invoke the method in the LAST component on that game object, which is usually not the case.

      The fix is simple. Adding a local variable should work.

      foreach (var mono in agent.gameObject.GetComponents<MonoBehaviour>())

      {

      ……

      var curMono = mono;

      CallbackEnter += (s)=>{ enterMethod.Invoke(curMono, new object[]{s}); };

      }

      #18887
      Gavalakis
      Keymaster

        Hey,

        Thanks! Even though I know of the trick, I totaly forgot to make use of it in the GatherDelegates method 🙂

        Thanks a lot. I will implement this now.

      Viewing 2 posts - 1 through 2 (of 2 total)
      • You must be logged in to reply to this topic.