Accessing addressable profile variables in runtime

Hi,

We’ve added a custom ContentVersion variable to our addressable profiles which is used when generating the build and load paths.
This works just fine but we would also like to display this content version in our splash screen for debug purposes.

This is what I initially tried:

AddressablesRuntimeProperties.EvaluateProperty("ContentVersion");

However, this doesn’t seem to work. Am I missing something simple here?

@at Same ^^^
I’m trying to get a SAS Token that I want to predefine at build time, but I’m having no such luck.

AddressablesRuntimeProperties.EvaluateProperty("SASToken");

Hey Everyone,

I wanted to note that the documentation found here, states the following.

Unity does not state where the reference needs to be in order for the field or property not to be stripped. If anyone knows how to reference a variable to prevent it from being stripped could you please let me know.

Thanks!

Let me flag this with the team for a bit of guidance. Which version of the Addressables package are you on?

@TreyK-47 com.unity.addressables@1.16.15 Thanks!

Thanks for the response, we’re also using 1.16.xx versions right now.

@TreyK-47 any updates?

Hey there @alecpilola ! No update yet, but I’ll ping them again.

Hey all, so I think the thing here is that you need to setup the data as part of a slightly customized build script. There’s a method AddressaablesRuntimeProperties.SetPropertyValue that you can use to setup the data during a build. So, create a custom build script and do something like:

public class NewBuildScript : BuildScriptPackedMode
    {
        protected override TResult BuildDataImplementation<TResult>(AddressablesDataBuilderInput builderInput)
        {
            var settings = AddressableAssetSettingsDefaultObject.Settings;
            var contentVersion = settings.profileSettings.GetValueByName(settings.activeProfileId, "ContentVersion");
            AddressablesRuntimeProperties.SetPropertyValue("ContentVersion", contentVersion);

            return base.BuildDataImplementation<TResult>(builderInput);
        }
    }

Then when you run that build script the data should be setup so at runtime you can call AddressaablesRuntimeProperties.EvaluateProperty like you’ve been doing. Unless I’m mistaken I don’t think that EvaluateProperty is meant to be used to get profile variables at runtime.

2 Likes

Perfect @davidla_unity !
I already have a customized build script. I just wasn’t sure how to register the properties.

Hey @davidla_unity ,
You use the following:

var contentVersion = settings.profileSettings.GetValueByName(settings.activeProfileId, "ContentVersion");

Is there anyway to evaluate that value in the editor?
I’ve tried evaluating using EvaluateString(String, String) here, but it doesn’t work.

So, EvaluateString is used to parse values from other variables you’ve created. So if you have “ContentVersion” as a profile variable you can have something like “Nightly Build Version” whose value is “[ContentVersion]-NightlyBuild” and Evaluate will convert that to the full value with whatever you have listed in ContentVersion. The big thing to note is the square brackets.

In the editor you should just be able to request the value using the GetValueByName and use the value directly.

Hopefully that helps? I’m not sure I fully understand your question so I apologize if not.

Sorry for the late reply @davidla_unity ,

I tried using this function in my custom build script to test the evaluation of values in the profile settings.

        [ContextMenu("EvaluateVariables")]
        public void EvaluateVariables()
        {
            var AddressableAssetSettings = AddressableAssetSettingsDefaultObject.Settings;
            var ProfileSettings = AddressableAssetSettings.profileSettings;
            var keys = ProfileSettings.GetVariableNames();
            foreach(var key in keys)
            {
                var value = ProfileSettings.GetValueByName(AddressableAssetSettings.activeProfileId, key);
                Debug.Log(key + ": " + value);
                var result = ProfileSettings.EvaluateString(AddressableAssetSettings.activeProfileId, key);
                Debug.Log(key + ": " + result);
            }
        }

The expected console output for the profile key of BuildTarget would be:

BuildTarget: StandaloneWindows64```

However, it is instead outputting:
```BuildTarget: [UnityEditor.EditorUserBuildSettings.activeBuildTarget]
BuildTarget: BuildTarget```

Is there something I am misunderstanding?

Regards, AlecPilola

[Edit]
After changing the function to this I am receiving the expected results;

```csharp
        [ContextMenu("EvaluateVariables")]
        public void EvaluateVariables()
        {
            var AddressableAssetSettings = AddressableAssetSettingsDefaultObject.Settings;
            var ProfileSettings = AddressableAssetSettings.profileSettings;
            var keys = ProfileSettings.GetVariableNames();
            foreach(var key in keys)
            {
                var value = ProfileSettings.GetValueByName(AddressableAssetSettings.activeProfileId, key);
                Debug.Log(key + ": " + value);
                var result = ProfileSettings.EvaluateString(AddressableAssetSettings.activeProfileId, value);
                Debug.Log(key + ": " + result);
            }
        }
2 Likes