Search Unity

Resolved Remote or local based on build platform

Discussion in 'Addressables' started by ManuBera, Jun 3, 2022.

  1. ManuBera

    ManuBera

    Joined:
    Aug 19, 2021
    Posts:
    70
    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 ;)

    Could someone help me with this?
     
  2. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    The best way you can do this is through the profile variables to a property.
    See the variable syntax at https://docs.unity3d.com/Packages/c...leAssetsProfiles.html#profile-variable-syntax
    e.g. if you have
    Code (CSharp):
    1. public class PlatformBasedProfileVariables
    2. {
    3.     public static string BuildPath
    4.     {
    5.         get
    6. #if UNITY_ANDROID
    7.         { return "[Local.BuildPath]"; }
    8. #endif
    9. #if UNITY_EDITOR
    10.         { return "[Remote.BuildPath]"; }
    11. #endif
    12.     }
    13. }
    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.
     
    ManuBera likes this.
  3. ManuBera

    ManuBera

    Joined:
    Aug 19, 2021
    Posts:
    70
    Oh wow, thank you very much!!
     
  4. ManuBera

    ManuBera

    Joined:
    Aug 19, 2021
    Posts:
    70
    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:

    Code (CSharp):
    1. public static class ModuleLoader
    2. {
    3.         public static string LoadPath
    4.         {
    5.             get
    6.             #if UNITY_WEBGL
    7.             { return "[Remote.LoadPath]"; }
    8.             #else
    9.             { return "[Local.LoadPath]"; }
    10.             #endif
    11.         }
    12. }
    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'."
     
    Last edited: Jun 14, 2022
  5. ManuBera

    ManuBera

    Joined:
    Aug 19, 2021
    Posts:
    70
    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 ;) Thanks again!