Remote or local based on build platform

Hey!

I would like to have all my WebGL builds use remote assets and all my other platform use local assets. I think it’s possible to do this with profile variables or something like that, but I can’t seem to find a quick and easy solution for this. At the moment I’m switching profiles manually every time I do a build for another platform, but this is of course not a good solution :wink:

Could someone help me with this?

The best way you can do this is through the profile variables to a property.
See the variable syntax at Profiles | Addressables | 1.20.5
e.g. if you have

public class PlatformBasedProfileVariables
{
    public static string BuildPath
    {
        get
#if UNITY_ANDROID
        { return "[Local.BuildPath]"; }
#endif
#if UNITY_EDITOR
        { return "[Remote.BuildPath]"; }
#endif
    }
}

Make a new build/load path pair say “Platform” and put “[PlatforBasedProfileVariables.BuildPath]” as its value. When it is used during the build, it will evaluate to the local variable on android and remote in editor.
Repeat for load path.

1 Like

Oh wow, thank you very much!!

Hmm… I’m not sure I’m doing it right. This is what I’m doing:

I have a static class that looks like this:

public static class ModuleLoader
{
        public static string LoadPath
        {
            get
            #if UNITY_WEBGL
            { return "[Remote.LoadPath]"; }
            #else
            { return "[Local.LoadPath]"; }
            #endif
        }
}

Then in Unity, in the Addressable Profile settings, I added “Build and Load Path Variables (All Profiles)” and entered:
ServerData/[BuildTarget] as BuildPath and [ModuleLoader.LoadPath] as load path. Remote.LoadPath and Local.LoadPath entries are set and should work. Now I made a UWP build, installed it and it throws errors, because it can’t connect to the remote address.

Any further help on this would be highly appreciated!

EDIT: Okay, I forgot to set the build/load paths for the Groups, but it still doesn’t work because it doesn’t seem to resolve the “[ModuleLoader.LoadPath]” and produces error messages like “‘ModuleLoader.LoadPath/709467f5ed520b11341e65740ccf1b9b_unitybuiltinshaders_fe3b4e03c75866b8061b1bbc5bc0d4f9.bundle’.”

Okay, I forgot to add the namespace of ModuleLoader to my path variable and I added the same thing for BuildPath and now it works. Just if someone has the same problem :wink: Thanks again!