Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity Multiplayer Server's heartbeat vanishes #49

Closed
MScottAdams opened this issue Apr 17, 2020 · 8 comments
Closed

Unity Multiplayer Server's heartbeat vanishes #49

MScottAdams opened this issue Apr 17, 2020 · 8 comments

Comments

@MScottAdams
Copy link

MScottAdams commented Apr 17, 2020

From https://github.com/PlayFab/UnitySDK/issues/226

Been chasing an issue where our game server loses its heartbeat. Our server actually switches scenes during its startup.

Root cause is missing code in PlayFabMultiplayerAgentView

Adding the following to the class fixed the issue:

public class PlayFabMultiplayerAgentView : MonoBehaviour
{
private float _timer;
/// <summary>
/// Awake constructor
/// </summary>
private void Awake()
{
    Debug.Log($"{Time.fixedTime} PlayFabMultiplayerAgentView awake ");

    // Need to keep this game object alive through scene changes.
    DontDestroyOnLoad(this);
}

/// <summary>
/// Called when gameobject is destroyed
/// </summary>
private void OnDestroy()
{
    Debug.Log($"{Time.fixedTime} PlayFabMultiplayerAgentView destroyed ");
}
@dgkanatsios
Copy link
Contributor

thank you!

@MScottAdams
Copy link
Author

Welcome! Sorry but I tried a couple of times but can't get the code indicators in the sample above working. It's probably easier to read it in original post on Unity SDK.

@dgkanatsios
Copy link
Contributor

I think I fixed that, let me know if code looks like intended now.

@MScottAdams
Copy link
Author

Thanks that is correct now!

@dgkanatsios
Copy link
Contributor

Coming back to this, want to make a pull request on this repo adding the DontDestroyOnLoad method? We'd be more than happy to review, discuss and accept!

@MScottAdams
Copy link
Author

Sorry as I mentioned before I just don't have the time currently to setup GIT and do all the required steps.

@CaptainPineapple
Copy link
Contributor

CaptainPineapple commented May 6, 2020

I'd go a bit further and suggest a singleton approach since depending on the scenes setup a scenechange might result in multiple Object getting created. Thus i'd suggest to add these following changes instead:

public class PlayFabMultiplayerAgentView : MonoBehaviour
{
    /// <summary>
    /// Static reference to the current active instance of the PlayFabMultiplayerAgentView.
    /// </summary>
    public static PlayFabMultiplayerAgentView current;
    private float _timer;
    /// <summary>
    /// Awake constructor
    /// </summary>
    private void Awake()
    {
        Debug.Log($"{Time.fixedTime} PlayFabMultiplayerAgentView awake ");
        // Check if the static instance already contains a refernce:
        if (current)
        {
            // Destroy this instance since we only ever need one PlayFabMultiplayerAgentView
            Destroy(gameObject);
            return;
        }
        else
        {
            // Need to keep this game object alive through scene changes.
            DontDestroyOnLoad(this);
            current = this;
        }
    }

    /// <summary>
    /// Called when gameobject is destroyed
    /// </summary>
    private void OnDestroy()
    {
        Debug.Log($"{Time.fixedTime} PlayFabMultiplayerAgentView destroyed ");
    }
}

CaptainPineapple added a commit to CaptainPineapple/gsdk that referenced this issue May 6, 2020
Warning: has yet to be tested
dgkanatsios pushed a commit that referenced this issue May 7, 2020
* added possible fix for issue #49

Warning: has yet to be tested

* changed tabs to spaces

* applied proposed changes to improve code maintainability and readability

fixed typo

* fixed variable name to capital C
@dgkanatsios
Copy link
Contributor

I believe we can close this due to #52, thanks @MScottAdams for bringing this up and @CaptainPineapple for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants