Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: jrDev on September 16, 2016, 07:26:52 PM

Title: Error Editing Field, Cannot Cast from Source Type to Destination Type
Post by: jrDev on September 16, 2016, 07:26:52 PM
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
Title: Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
Post by: Alex Chouls 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?
Title: Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
Post by: jrDev 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
Title: Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
Post by: jrDev 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
Title: Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
Post by: Alex Chouls 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?
Title: Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
Post by: jrDev 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
Title: Re: Error Editing Field, Cannot Cast from Source Type to Destination Type
Post by: jeanfabre 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