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 SDK - Initialize in Awake() #1338

Merged
merged 1 commit into from
Feb 12, 2020

Conversation

mollstam
Copy link
Contributor

We ran into an issue where AgonesSdk was used before it was initialized due to the fact that we keep the game object deactivated (checkbox unticked in editor) only to activate it when running as the game server. Activating the game object (thus activating the AgonesSdk MonoBehaviour) calls Awake() but Start() isn't called until "before the next Update()" which might be up to a frame later.

We ended up calling WatchGameServer(...) before sidecarAddress has been set (in Start()) so the watch request was sent to "http://localhost/watch/gameserver" instead (since the request was created with only the path component).

This PR moves the sidecarAddress init to Awake() so that when the MB has been "awoken" it is ready to be used. I left the health check kick-off in Start() as it felt more "internal start logic" than "init state", if that makes sense.

Feedback appreciated. 🙂

Awake() is more commonly used to initialize variables as it is
guaranteed to run as soon as the game object is instantiated or
activated. Start() is called before the first Update(), which
might be up to a frame later.

See Unity docs for reference
https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: c377728d-2f9f-4d3c-ad2a-3016a38ffcad

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1338/head:pr_1338 && git checkout pr_1338
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.4.0-8462451

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mollstam, roberthbailey

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@markmandel markmandel merged commit 7c689b7 into googleforgames:master Feb 12, 2020
@markmandel markmandel added the area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc label Feb 12, 2020
@markmandel markmandel added this to the 1.4.0 milestone Feb 12, 2020
@mollstam mollstam deleted the feature/unity-use-awake branch February 13, 2020 05:14
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
Awake() is more commonly used to initialize variables as it is
guaranteed to run as soon as the game object is instantiated or
activated. Start() is called before the first Update(), which
might be up to a frame later.

See Unity docs for reference
https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc lgtm size/XS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants