playMaker

Author Topic: Error Editing Field, Cannot Cast from Source Type to Destination Type  (Read 3095 times)

jrDev

  • Junior Playmaker
  • **
  • Posts: 59
Hey guys,

I have this code below where I want to add an object value to an Object Array Type:

Code: [Select]
object functionResults;

[ArrayEditor(VariableType.Object)]
public FsmArray theFunctionResult;

theFunctionResult.Values = new object[1];
theFunctionResult.Values.SetValue(functionResults, 0);

But this code throws this error "Error Editing Field The Function Result, Cannot Cast from Source Type to Destination Type" when I play it. See pic in attachment. How can I get this to work?

Thanks,
jrDev

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
« Reply #1 on: September 16, 2016, 10:46:26 PM »
VariableType.Object refers to a UnityEngine.Object type.
So the array can store UnityEngine.Object references.

object is a system.object type so is incompatible.

What are you trying to store in the FsmArray?

jrDev

  • Junior Playmaker
  • **
  • Posts: 59
Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
« Reply #2 on: September 17, 2016, 11:13:19 AM »
Hey,

I want to store text files...

And with that I modified it to say:

Code: [Select]
[ArrayEditor(typeof(object))]
public FsmArray theFunctionResult;

But this:

theFunctionResult.Values = new object[1];

Doesn't make the arrays length to one, it stays at zero.

Thanks,
jrDev
« Last Edit: September 17, 2016, 11:17:24 AM by jrDev »

jrDev

  • Junior Playmaker
  • **
  • Posts: 59
Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
« Reply #3 on: September 17, 2016, 11:23:35 AM »
Hey,

Actually after some debug logging, it looks like my object value does get stored in the array based on the above code, it just doesn't show in Playmaker State GUI section. Is this a bug?

Thanks,
jrDev

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
« Reply #4 on: September 17, 2016, 12:41:28 PM »
An FsmArray cannot serialize a system.object type. Why not use a string type if you're storing text?

jrDev

  • Junior Playmaker
  • **
  • Posts: 59
Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
« Reply #5 on: September 18, 2016, 11:22:02 PM »
An FsmArray cannot serialize a system.object type. Why not use a string type if you're storing text?
Is there a reason why I can't store an system.object type in a Unity.Object type?

Thanks,
jrDev

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
« Reply #6 on: September 26, 2016, 03:32:56 AM »
Hi,

 Serialization in Unity is complex and indeed System.object and Unity.Object are not the same.

Can you describe the object you are trying to save?

Bye,

 Jean