Search Unity

Question Game does not load external files

Discussion in 'Web' started by nexxxx, Mar 3, 2024.

  1. nexxxx

    nexxxx

    Joined:
    Feb 4, 2021
    Posts:
    4
    Hi
    I have a problem loading external game files in webgl. in the windows version everything works without any problems. Do web games use different file pointing? The game loads external files required for operation and the browser version will not run at all. Maybe someone can advise what may be wrong.



    I want to run this project in the browser: https://github.com/slavidodo/OpenTibia-Unity
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,838
    Web applications are prohibited from using the file system API. If that "external file" is in a location like the user's home directory, the app cannot access that. You will have to make those files available via a webserver / webservice or cloud drive, or bundle them within the app itself by using the StreamingAssets folder.
     
    nexxxx likes this.
  3. nexxxx

    nexxxx

    Joined:
    Feb 4, 2021
    Posts:
    4
    thank you for the information. I tried to share these files on my server where the game is hosted, but these files still cannot be loaded. gives an absolute address with https and a relative one and it doesn't work. see the files are visible here: https://zanera.pl/client/StreamingAssets/860/
    but the unity game doesn't see them. how to specify the path to these files? I've tried every method.
     
  4. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,709
    How are you trying to load them?
     
  5. nexxxx

    nexxxx

    Joined:
    Feb 4, 2021
    Posts:
    4
    Code (CSharp):
    1.         protected void LoadProtoAppearanaces(string assetsPath) {
    2.             string appearancesPath = Path.Combine(assetsPath, "appearances.otud");
    3.             if (!File.Exists(appearancesPath))
    4.                 throw new FileNotFoundException(string.Format("Couldn't find the appearances ({0}).", appearancesPath));
    5.          
    6.             try {
    7.                 byte[] bytes = File.ReadAllBytes(appearancesPath);
    8.                 AppearanceStorage.SetProtoAppearances(Protobuf.Appearances.Appearances.Parser.ParseFrom(bytes));
    9.             } catch (System.Exception e) {
    10.                 throw new System.Exception(string.Format("Unable to appearances.otud ({0}).", e.Message));
    11.             }
    12.         }

    Code (CSharp):
    1.         public string GetAssetsPath(int clientVersion, int buildVersion, ClientSpecification specification) {
    2.             string assetsPath;
    3.             if (clientVersion >= 1100)
    4.                 assetsPath = string.Format("{0}.{1}", clientVersion, buildVersion);
    5.             else
    6.                 assetsPath = clientVersion.ToString();
    7.  
    8.             assetsPath = Path.Combine(Application.streamingAssetsPath, assetsPath);
    9.             return assetsPath;
    10.         }
     
  6. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,709
    so im guessing something goes wrong in your GetAssetsPath, where your assetsPath is clientversion.buildV|ersion - wheres the . in your path? is it because its expecting to find some form of subfolder?