NavMeshAgent not persisting

Discussion and help for Easy Save 3
Post Reply
jeffsim
Posts: 9
Joined: Tue Jul 23, 2019 2:02 pm

NavMeshAgent not persisting

Post by jeffsim »

... well, sometimes. Here's the simplest (contrived) test case I could create to reproduce it.

Code: Select all

using UnityEngine;
using UnityEngine.AI;

public class Argh : MonoBehaviour
{
    public bool createAndSaveObjThisTime = true;

    // To reproduce: 
    //   1. Create an empty gameobject in a new project; attach this script to it.
    //   2. Remove autosavemgr component (just in case that's causing it)
    //   3. in editor check "createAndSaveObjThisTime" and run the app; see 2 comps created and loaded
    //   4. in editor stop the app, uncheck"createAndSaveObjThisTime", and start the app; see 1 comp loaded
    void Start()
    {
        if (createAndSaveObjThisTime)
        {
            // create the test obj
            GameObject testObj = new GameObject();
            testObj.AddComponent<NavMeshAgent>();
            Debug.Log("# component(s) saved (should be 2): " + testObj.GetComponents(typeof(Component)).Length);

            // save it
            ES3.Save<GameObject>("myTestObj", testObj);
        }

        // load it, verify # comps match
        GameObject loadedObj = ES3.Load<GameObject>("myTestObj");
        Debug.Log("# component(s) loaded (should be 2): " + loadedObj.GetComponents(typeof(Component)).Length);
    }
}
When I run the app with the checkbox checked (to create the object) it outputs "2 components saved / 2 components loaded". When I stop to app, uncheck the checkbox, and start the app, it says "1 component loaded". I'm not sure why it'd save/load properly the first time but not the second.

Please help!

Thanks,
Jeff
jeffsim
Posts: 9
Joined: Tue Jul 23, 2019 2:02 pm

Re: NavMeshAgent not persisting

Post by jeffsim »

Ah, figured out my own problem. Here's what was going on in case anyone else runs into this:

1. Afaict, the reference to the NavMeshAgent was still present in memory when loading the first time, so it was showing up in ES3's refmgr. (That may not be quite right, but something like that). That was misleading me down the wrong path, as it loaded the first time but not the second.
2. I had earlier looked up the NavMeshAgent in the ES3 Types dialog, but didn't realize it was case-sensitive so when it didn't show up I assumed it was built-in or somesuch (I'm new to ES3 and was making assumptions). I then saw a thread saying it's case sensitive, which makes sense.
3. To fix: I went back to the ES3 types dialog, added the NavMeshAgent type there, checked some checkboxes in there, and things are working better.

A couple of possible QoL features from a new user's POV:
* In the ES3 types dialog, if no matches then see if there's a case-insensitive match then add "did you mean [NavMeshAgent]" style helper text.
* In that dialog, NavMeshAgent allows checking things like the "updatePosition" function. I'm not sure if there's a common case for that, but it'd be nice to have a 'smart select' button (in addition to the existing 'all') that selects only the properties that are not functions as a starting point.

Cheers
Jeff
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: NavMeshAgent not persisting

Post by Joel »

Hi Jeff,

Thanks for the feedback, that's really helpful.

The reason we don't allow case insensitive search is that the list of types is so large that we've had issues with lag when searching without case sensitivity. Being able to offer helper text in that way would still require a case insensitive search. However, I'll see if there's any options to improve performance in later versions of Unity.

With regards to your second suggestion, I'm not sure I understand what you mean by "properties that are not functions". Would you be able to clarify? Functions do not themselves contain any data, so it's not possible to save/load functions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
jeffsim
Posts: 9
Joined: Tue Jul 23, 2019 2:02 pm

Re: NavMeshAgent not persisting

Post by jeffsim »

Hi Joel,

> The reason we don't allow case insensitive search...

That makes sense, thanks!

> With regards to your second suggestion, I'm not sure I understand what you mean by "properties that are not functions". Would you be able to clarify? Functions do not themselves contain any data, so it's not possible to save/load functions.

Sorry about the confusion - I realized that it's not actually listing functions, so it's a non-ask. I saw "updatePosition" in NavMeshAgent and assumed incorrectly that it was a function. All good as is :).

Thanks!
Jeff
Post Reply