Welcome, Guest

Author Topic: Action<T> is never call()d  (Read 1585 times)

mindlube

  • Posts: 63
    • View Profile
Action<T> is never call()d
« on: May 13, 2014, 08:53:25 AM »
Before I file a bug report, are there any known issues with Action<T> or can you spot anything dumb I've done below? Is there any way to debug why engine.call() from javascript doesn't work sometimes? I am simply trying to round-trip a C# data model to javascript and back.

C# model class
Code: [Select]
#if (UNITY_IPHONE || UNITY_ANDROID) && ! UNITY_EDITOR
using Coherent.UI.Mobile.Binding;
#else
using Coherent.UI.Binding;
#endif

[CoherentType(PropertyBindingFlags.All)]
public class PrefsModel
{
// bunch of public properties...
}

C# ui controller
In the coui view's OnReadyForBindings delegate, I register the Call, and I also send an event with the model to javascript

Code: [Select]
uiViewMain.View.RegisterForEvent("Error", (Action<string>)OnUIError);
uiViewMain.View.BindCall("OnUIPrefs", (Action<PrefsModel>)OnUIPrefs);
// some other BindCalls
// ...
// marshall the preferences model to coherentui
uiViewMain.View.TriggerEvent<PrefsModel>("OnPrefs", Prefs.instance.model);

Javascript
Code: [Select]
// global var
var cd3Prefs = null;
// receive prefs marshalled from unity
engine.on('OnPrefs', function(prefs) {
    // store in global var
    cd3Prefs = prefs;
  });

// later, in a button click
console.log('Calling OnUISetPrefs w/');
console.log(cd3Prefs);
engine.call('OnUIPrefs', cd3Prefs);

Here is the method that is never called

 
Code: [Select]
public void OnUIPrefs(PrefsModel model)
  {
    var json = JsonConvert.SerializeObject(model);
    Debug.LogWarning("OnUIPrefs " + json);
  }
In the javascript debugger there are no errors, and it appears that cd3Prefs is a fully populated object with the correct __Type. So the C# -> javascript binding is working fine, but the return direction is not working. See screenshot for the output of the javascript call. But the call is never fired on the Unity3d side. Very mysterious! No errors, either on the javascript side, nor in my Error event handler.

  Unity 4.3.4, CU 1.8.1
« Last Edit: May 13, 2014, 08:58:28 AM by mindlube »

mindlube

  • Posts: 63
    • View Profile
Re: Action<T> is never call()d
« Reply #1 on: May 13, 2014, 11:05:18 AM »
I'm about to implement some seriously ugly- hackish workarounds. I am at my wits end with this one. Are there any datatypes that are not supported by the coui bindings? My C# data model uses:
string, bool, float, byte, and Enums

mindlube

  • Posts: 63
    • View Profile
Re: Action<T> is never call()d
« Reply #2 on: May 13, 2014, 12:31:17 PM »
Found it.
Code: [Select]
 //  this fails when Method is an Action<T> where T has a property of type "byte". 
engine.call("Method", obj)
Maybe it fails for other types too, like Enums. Donnow. It definitely fails *silently* for byte.
« Last Edit: May 13, 2014, 12:32:28 PM by mindlube »

Hristo

  • Guest
Re: Action<T> is never call()d
« Reply #3 on: May 15, 2014, 01:13:29 AM »
Hi mindlube,

Thanks for reporting this. We managed to reproduce it and we are currently working on a solution. I'll update you as soon as we have more information.

Tags: