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.
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.
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.
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.
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);
}
}