2018.3 Prefabs

Forums General Discussion 2018.3 Prefabs

This topic contains 7 replies, has 2 voices, and was last updated by  Gavalakis 2 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2042

    net8floz
    Participant

    Hi. I noticed the change logs say the latest versions of both flow and node are tested for 2018.3. However when I use prefabs and flow/node I get an insane amount of problems. Serialization errors, data loss, etc. How can I contribute? I’d like to get up and running with 2018.3 asap. Thanks for all your hard work too.

    #2053

    Gavalakis
    Keymaster

    Hello,

    Hmm. Can you please clarify what errors you get more specifically?
    I just re-checked using FlowCanvas v2.8.5 in Unity v2018.3 with prefabs and I can’t see any problems with that.
    Please let me know what problems you’ve faced and how to reproduce those.

    Thank you.

    #2055

    net8floz
    Participant

    Sure there’s quite a bit so I’ll need some time to prepare. Is there a good email address for sending projects or should I just upload publicly and remove the paid flow/node source?

    #2056

    net8floz
    Participant

    Thanks for the reply and your work on the assets. To start with a few things:

    1 – ( see attached image ). Serialization is mismatching types. It says “FlowScriptController” here but the type isn’t actually important, it’s a public field on a custom FSM task with a scene reference attached. The fact that it’s one of your component types as that public field is coincidental – it could be any class.

    2 – Blackboard variables do not persist. If I open a prefab, add, remove, or change blackboard variables any prefab instances will not be updated resulting in data loss and other issues. It does work somteimes but will eventually become unusable.

    3 – Prefab management is a bit wonky. It always has prefab overrides on the instance with no way to “Revert” or “Apply” ( these both seem to do nothing when working with and paradox components ). I’d recommend testing working with a prefab instance in a scene, opening it in the new prefab editor and making changes, going back to the scene and see how everything reacts. It’s very troublesome.

    I’ve attached a project where you can experience all of these things yourself with your source plugins removed. It’s hard exactly to pinpoint more errors as it just all seems to fail everywhere after this point, maybe due to (1) serialization error. Basically anything I do when using a prefab results in a ton of errors I’ll try and get more specific as we go along I apologize if this comes off a bit vague.

    – Open project
    – Import node / flow canvas from asset store ( I put them in Plugins folder – it would probably be best for me to just email you a full project privately )
    – Press Play or otherwise try and do any development.

    Attached project: ( forums would not let me upload ) https://drive.google.com/file/d/1m6nAsMguFeSvfZar2MSNtSBd8pgzXySb/view?usp=sharing

    Attachments:
    You must be logged in to view attached files.
    #2058

    net8floz
    Participant

    Update

    Today I implemented flow canvas in another existing project and reworked my objects into prefab variants with flow canvas controllers and everything went as expected no errors. So whatever I’m doing with the custom task must just be throwing a wrench in the whole thing.

    I went back to the project I submitted earlier and did some more testing. If you unpack the prefab completely it will run, I even filled out some flow scripts and everything was fine.

    The moment I set it up as a prefab I start getting errors so I think there’s some issues with the serialization of node canvas I’m triggering somehow but flow canvas does seem to be up and running in 2018.3 =D

    I did however notice that the way blackboard variables work ( forgive me if I’m misunderstanding what’s happening ) are not compatible with prefab variant workflows since they’re stored as a single string which explains some of my confusion about data loss there. I might suggest storing them as individual json parts during edit and creating a final serialized string separately to use at runtime. This would be a great addition! In the mean time I’m going to try my hand at extending the blackboard to support this.

    I managed to hack it in =P

    
            [SerializeField] private List<string> _serializedVariables = new List<string>();
    
            //serialize blackboard variables to json
            void ISerializationCallbackReceiver.OnBeforeSerialize() {
    #if UNITY_EDITOR
                if (JSONSerializer.applicationPlaying) {
                    return;
                }
    
                if (_objectReferences != null && _objectReferences.Count > 0 && _objectReferences.Any(o => o != null)) {
                    hasDeserialized = false;
                }
    
                _objectReferences = new List<UnityEngine.Object>();
    
                _serializedBlackboard = JSONSerializer.Serialize(typeof(BlackboardSource), _blackboard, false, _objectReferences);
                var data = fsJsonParser.Parse(_serializedBlackboard);
                var variables = data.AsDictionary["_variables"].AsDictionary;
    
                _serializedVariables.Clear();
                foreach (var item in variables) {
                    _serializedVariables.Add("\"" + item.Key + "\": " + item.Value);
                }
    #endif
            }
    
            //deserialize blackboard variables from json
            void ISerializationCallbackReceiver.OnAfterDeserialize() {
                if (hasDeserialized && JSONSerializer.applicationPlaying) {
                    return;
                }
                hasDeserialized = true;
    
    #if UNITY_EDITOR
                if (!JSONSerializer.applicationPlaying) {
                    var json = "{\"_variables\":{";
                    for (int i = 0; i < _serializedVariables.Count; i++) {
                        var item = _serializedVariables;
                        json += item;
                        if (i != _serializedVariables.Count - 1) {
                            json += ",";
                        }
                    }
                    json += "}}";
                    _blackboard = JSONSerializer.Deserialize<BlackboardSource>(json, _objectReferences);
                } else {
                    _blackboard = JSONSerializer.Deserialize<BlackboardSource>(_serializedBlackboard, _objectReferences);
                }
    #else
                _blackboard = JSONSerializer.Deserialize<BlackboardSource>(_serializedBlackboard, _objectReferences);
    #endif
                
                if (_blackboard == null) _blackboard = new BlackboardSource();
            }
    
    #2059

    Gavalakis
    Keymaster

    Hello and sorry for the late reply!

    Indeed, blackboard variables are serialized all together in the json. In fact the Blackboard object itself is, rather that only the variables. I will however take a closer look at your implementation and if it’s something that won’t break backwards compatibility I would be more than glad to use it though! 🙂

    About the serialization issue you are facing, I want to let you know that I am still looking at that. It seems to be something weird about new Unity prefabs. It’s also weird that it only throws the first time I press play in your example project (thanks for providing that by the way).

    I will update this thread once I manage to pinpoint what the problem actually is.

    Thank you!

    #2063

    net8floz
    Participant

    No worries we’re all busy. I’m using flowcanvas in two different 2018.3 projects and at this point I’m feeling pretty comfy with it’s current prefab pitfalls.

    My soultion works just fine ( I’ve made some fixes to it locally since posting though ) except when I deserialize it doesn’t populate object references even though I’m passing it the known object collection and I can’t understand why.

    Out of this issue came an actually really handy component. I create a new blackboard component that extends from the vanilla one called “CommonBlackboard”. I put this on my root prefab game object and it holds common variables that exist for all variants but may not have any actual data yet ( as this is the job of the variant to populate with specifics ).

    Then the blackboard variables throughout the prefab go look at the common blackboard during editor time ( I create a static MenuItem function that loops through all prefabs and attempts to resolve and then save those assets) using another component CommonBlackboardLoader which lives with the vanilla blackboard.

    A bit complicated maybe but it’s been working really well for me. I would say that having something to make blackboards and prefab variants / nested prefabs managable is a must going forward otherwise it breaks a lot of desired workflow. Though you can probably find something more clever than my solution above. The same is true for the actual flow scripts, they are not variant compatible but I think this is less important and just using the asset version instead of bound is fine. It works and doesn’t break the workflow.

    And yes it was like that in my actual projects too – it fails to play every other time like clockwork. Very odd.

    Anyways if there’s any other information I can provide to help with your 2018.3 update please ask away – I’ve also gotten quite comfy with the new prefab system and PrefabUtility if that info can be of help to you in any way.

    Even though I’m an experienced programmer flow canvas has helped me move away from writing lots of specific scripts and instead going with data driven events and I’m pretty happy with it!

    ( and as a side note if you started a discord server I would hang out and help answer questions )

    #2065

    Gavalakis
    Keymaster

    Hello again and thanks for the follow up and details 🙂

    I do agree that it would be very nice for blackboard as well as graphs to an extent to be more prefab variant compatible somehow. For blackboard it certainly makes more sense that graphs themselves. I will look at possible solutions about this (one possibility is definitely yours by the way) and see what could be done without breaking backwards compatibility (which is always a pain :)).

    If I come by any questions I will let you know, thanks!
    A Discord channel is something I have been thinking about more recently, so it might happen in the future.

    Thank you for your positive feedback. I am really glad you like FlowCanvas 🙂

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.