alelievr / NodeGraphProcessor

Node graph editor framework focused on data processing using Unity UIElements and C# 4.6
https://github.com/alelievr/NodeGraphProcessor/projects/2
MIT License
2.3k stars 386 forks source link

ScriptableObject reference on node possible? (null in build) #81

Closed jejelite closed 3 years ago

jejelite commented 4 years ago

Is it's possible to serialize scriptableObject reference? Everything is working in editor but in a build the variable "AiAction" is null when the node is evaluated.

[System.Serializable, NodeMenuItem("Obsolete/AiAction")]
public class AIActionNode : LeafNode
{
    [SerializeField] private AIAction action = null;

    [Input(name = "AIMaster", allowMultiple = false)]
    public AIMaster aiMaster;

    protected override NodeState OnEvaluate()
    {
        return aiMaster.DoAction(action);
    }
}

image

alelievr commented 4 years ago

Hello, from what I looked it's a limitation of the JSON serialization system implemented in Unity.

Fortunately, I plan to refactor the serialization system with [SerializeReference] instead of JSON to fix a bunch of issues like this one but I need to wait for this issue to be backported in 2019.4 before landing the changes (it should happen within a couples of weeks). I'll update this issue when the refactor lands.

jejelite commented 4 years ago

All good, keep up the good work! , for people having the same problem a good workaround is replacing the input by a string representing a id of the ScriptableObject inside a dictionnary<String, YourScriptableObject> and call it from a Monobehavior.

Thanks for the support.