immersivecognition / unity-experiment-framework

UXF - Framework for creating human behaviour experiments in Unity
https://immersivecognition.github.io/unity-experiment-framework/
MIT License
221 stars 43 forks source link

How to I check whether a certain key can be found in the settings heirarchy? #155

Closed JAQuent closed 1 year ago

JAQuent commented 1 year ago

I'd like to check if my session .json contains a certain key (e.g. objectRotationSpeed) and use that value if it exists and assign a default value if it doesn't. For that I have to check whether the key objectRotationSpeed exists in the settings heirarchy but I don't know how to do this.

Something like:

if(session.settings.GetFloat("objectRotationSpeed") == null){
\\\\ Assigning default value
}

But if I do this I get the following error: KeyNotFoundException: The key "objectRotationSpeed" was not found in the settings heirarchy. Use UXF Session Debugger (UXF menu at top of unity editor) to check your settings are being applied correctly.

JAQuent commented 1 year ago

I've tried to use this https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.keycollection?view=net-8.0 by accessing session.settings.Keys.Contains(key) because session.settings.Keys seem to be a 'Dictionary<string, object>.KeyCollection' , however I still get

error CS1061: 'Dictionary<string, object>.KeyCollection' does not contain a definition for 'Contains' and no accessible extension method 'Contains' accepting a first argument of type 'Dictionary<string, object>.KeyCollection' could be found (are you missing a using directive or an assembly reference?)

JAQuent commented 1 year ago

This works

        foreach(var key in session.settings.Keys){
            Debug.Log(key);
        }