Adjust ServerSettings at runtime?

Options
My game connects to a central update server at startup, and I would like to be able to adjust any necessary Photon settings via this update server. For example, if Photon Cloud goes down I would like to be able to host my own server and temporarily point all my released games to it.

For some reason, Photon's ServerSettings seem to be stored as static members of a nonstatic serialized ScriptableObject. How do I access and change them at runtime? The code I have:
public static ServerSettings PhotonServerSettings = (ServerSettings)Resources.Load (Path.GetFileNameWithoutExtension (NetworkingPeer.serverSettingsAssetPath), typeof(ServerSettings));
PhotonServerSettings.DefaultMasterPort = 5005;

Results in this error:
error CS0176: Static member `ServerSettings.DefaultMasterPort ' cannot be accessed with an instance reference, qualify it with a type name instead

Comments

  • dreamora
    Options
    don't use the settings at all but PhotonNetwork.Connect and you don't have the problem (I don't touch the settings and even unhooked its annoying automatic code that shows you that stupid configuration screen on every leave of play mode if you refuse to configure it as you never use the connect with settings function)
  • Fair enough ;)

    Thanks for the tip!
  • Tobias
    Options
    The settings are not exactly built to be modified at runtime. We simply didn't see this usecase.
    The settings file and wizard is just one (simple) way to connect - using Connect() directly is as good.
  • Ishwar
    Options
    When I connect to Best Region and Random Room, I am at the mercy of Photon server settings. This caused the player characters to end up in different regions and hence could not be in one room.
    To avoid it I am trying to 'Connecttoregion'. When I do this, it is giving error on ap Id. I am searching for pun connect call with programmatic control of app settings. I thought I could get all app settings using "PhotonNetwork.PhotonServerSettings.AppSettings;" and then update the same with what I changed i.e. the region.
    I am not able to find any api that updates it.

    Or is there any other way to achieve this? I want to be able to connect to specific region. connecttoregion returns with error on App Id.

    thanks.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Ishwar,

    As we have explicitly added to the "Migration Notes".
    In PUN2, ONLY PhotonNetwork.ConnectUsingSettings() makes use of PhotonServerSettings.

    If you want to connect a specific region, set it in PhotonServerSettings.AppSettings.FixedRegion (in Editor or via code) first then call PhotonNetwork.ConnectUsingSettings().
  • Ishwar
    Options
    Thanks a lot. I just found that 'PhotonNetwork.PhotonServerSettings.AppSettings' returns me the reference (not a copy). Hence the below code worked for me.

    myAppSettings = PhotonNetwork.PhotonServerSettings.AppSettings;
    myAppSettings.FixedRegion = "us";
    PhotonNetwork.ConnectUsingSettings();

    Unless you suggest any down side to this, I will use this. Thanks!
  • iamtagir
    Options
    Thank you!