Search Unity

Url parameters interfering with playerprefs?

Discussion in 'Web' started by TestTubeGames, Apr 18, 2021.

  1. TestTubeGames

    TestTubeGames

    Joined:
    Dec 9, 2014
    Posts:
    5
    I've got a webgl game that lets players make creations, saving them with playerprefs.

    I also added a way to share those creations with each other, by using a link with some parameters in the url -- basically like "https://basicsite.com/thegame.html?creation=abc123"

    What I'm running into is a problem where in some browsers (firefox on mac), this seems to be treated as a different url for playerprefs purposes. So if someone uses that link, they won't find their saves. On the flip side, if they make *new* saves to playerprefs while at that url, it will be gone when they reload the game with the standard url.

    In some browsers (chrome on mac), this doesn't happen, it all saves fine.

    I'm curious if other folks have run into this before -- I'm not having much success googling. And if there are any tricks folks might know to get around this.

    Thanks!
     
  2. NickoG

    NickoG

    Joined:
    Apr 19, 2015
    Posts:
    8
    You must have the saving disabled while visiting another player? I have a game with similar functions and I have to transfer the URL parameter into the actual iframe embed code url, which just takes a few extra lines above the embedded game. Then when the game starts it won't initialize the load/save function if the player is visiting a another player.
    And if the url is clean it will do a basic load from file.
     
  3. NickoG

    NickoG

    Joined:
    Apr 19, 2015
    Posts:
    8
    Actually don't have to do that, it's just how I ended up doing it
    The challenge was that the game/ iframe couldn't access the browser url. But the page can access the iframe. So have to make sure to tell the game about the url parameters before it does any load function. (Interacting with browser code) : I guess I could put it in a var on the site that the game has access to, doesn't have to be the src.
     
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Having a behavior here that is different across Firefox and Chrome is quite interesting. It does suggest that maybe one of the browsers has a bug here. It would be great if you can report a bug to Unity, and we can triage it and route it to either Firefox or Chrome issue trackers to investigate.