playMaker

Author Topic: Unity Serializer Won't Deserialize FSMObject  (Read 4126 times)

recarik

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Unity Serializer Won't Deserialize FSMObject
« on: May 09, 2015, 08:50:39 AM »
When I try to load a level Unity shows this error:
Code: [Select]
Serialization error: Serialization.UnitySerializerProject+MissingConstructorException: Could not construct an object of type 'System.MonoType',
it must be creatable in this scope and have a default parameterless constructor or you should handle the CreateType event on UnitySerializer to construct the object

I tried to change the Behavior of the FSMObject, but it's the same. The serializer will serialize and deserialize the component if I attach it to a GameObject.
Instead in the FSMObject it serialize the object, but Unity Serializer doesn't serialize it. The class is an empty class and the FSMObject can be null, because the value is assigned by GetComponent Action.

Any idea?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #1 on: May 09, 2015, 11:56:57 AM »
Hi,

 What class is the FsmObject targeting?

 Bye,

 Jean

recarik

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #2 on: May 10, 2015, 08:55:39 AM »
This is the code of the class:
Code: [Select]
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Serialization;

[System.Serializable]
public class ArtificialIntelligence : DestructibleObject
{


}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #3 on: May 21, 2015, 04:03:54 AM »
Hi,

 yeah, but since it doesn't seem to serialize deserialize it, I need to see the content as well :)

 pm me if you don't want this to be public.

Bye,

 Jean

recarik

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #4 on: May 25, 2015, 12:05:41 PM »
Hi,

If you need the class DestructibleObject, it's an empty class too.
Do u need Playmaker Actions?

Bye

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #5 on: May 25, 2015, 11:39:04 PM »
Hi,

 I am confused then. if your classes are empty of any serializable property ( public variables or private variable explicitly declared as serializable), what do you expect to be serialized?

Maybe I am not asking the right question :)

your class "ArtificialIntelligence" doesn't have any content, so nothing will be serialized. If you had something like:

Code: [Select]
[System.Serializable]
public class ArtificialIntelligence : DestructibleObject
{

  public bool myFlag;
}

then myFlag would be serialized. provided somewhere else, you have created an instance of that ArtificialIntelligence and for example set myFlag to true, and then referenced that instance in an FsmObject.



Bye,

 Jean

recarik

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #6 on: May 31, 2015, 03:07:26 AM »
So I deduce serializer works only with a non-empty class, right?

If I want to serialize a FSM with an object Variable which is an empty behavior,do I have to add a variable to the script to serialize the FSM?

Bye,

recarik

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #7 on: June 03, 2015, 11:59:43 PM »
Hi,

 yeah of course, well, it only make sense if class have things inside them to serialize.

I am really lost at what you are trying to achieve here. I think there is a misconception somewhere in your thinking process.

What would be the point in your project to have an empty behavior? by definition an empty behavior will do nothing and host no variables, and so it will not be useful, and therefore totally unnecessary.

if you create a behavior, it's to server a very specific purpose, so in your case, what os the purpose of this empty behavior? if you can explain this, then I am likely to understand what you want to achieve and help you out better.

Bye,

 Jean

recarik

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #8 on: June 04, 2015, 11:31:23 AM »
Hi,

I think you know what is an AI. I want to use this class only to create derivate class in which I can add more behaviors. It's a base class to recognize enemy, NPC etc.

Bye,

recarik

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #9 on: June 04, 2015, 12:21:49 PM »
Hi,

 ok, then if this is a base/abtract/virtual class, it must be derived by other classes, which will hold some data, and then this is the data that will be serialized.

Do you have an example of this kind of class that use this base class?

 also, a base class that is empty is likely not worth the effort, a base class should at least share some common features, such as common data ( the name of the object typically or common methods).

Bye,

 Jean

recarik

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #10 on: June 05, 2015, 10:03:22 AM »
Hi,

this is a simple derived class that I use for simple AI:
Code: [Select]
using System;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;

[RequireComponent(typeof(Seeker), typeof(PlayMakerFSM))]
public class GoToPontAndDoAI : ArtificialIntelligence
{

    public GameObject Target
    {
        get { return target != null ? target.gameObject : null; }
        set { target = value.transform; }
    }

    public Transform target;
    public float speed = 2;
    public string eventName = "ON PATH COMPLETE";
    Seeker seeker;
    Path path;
    int currentWaypoint = 0;
    public float nextWaypointDistance = 3;

    void OnEnable()
    {
        seeker = GetComponent<Seeker>();
        seeker.StartPath(transform.position, target.position, OnPathComplete);
    }

 
    protected void Update()
    {
     

        if (path == null)
        {
            return;
           
        }

        if (currentWaypoint >= path.vectorPath.Count)
        {
            GetComponent<PlayMakerFSM>().Fsm.Event(eventName);
            path = null;
            return;
        }
        Vector3 dir = (path.vectorPath[currentWaypoint] - transform.position);
        dir *= speed * Time.deltaTime;
        GetComponent<Rigidbody2D>().MovePosition(transform.position + dir);

     
        if (Vector3.Distance(transform.position, path.vectorPath[currentWaypoint]) < nextWaypointDistance)
        {
           
            currentWaypoint++;
            return;
        }
    }
    void OnPathComplete(Path p)
    {
        if (!p.error)
        {
            currentWaypoint = 0;
            path = p;
        }
    }
}

Bye,

recarik

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14564
  • Official Playmaker Support
    • View Profile
Re: Unity Serializer Won't Deserialize FSMObject
« Reply #11 on: June 15, 2015, 10:24:40 PM »
Hi,

 ok, and so you need to add an attribute [System.Serializable] here too. I don't see it in the class definition.

Is DestructibleObject a Component?

 Bye,

 Jean