-
Notifications
You must be signed in to change notification settings - Fork 140
Conversation
@@ -67,7 +67,8 @@ bool USpatialGameInstance::HasSpatialNetDriver() const | |||
|
|||
void USpatialGameInstance::CreateNewSpatialWorkerConnection() | |||
{ | |||
SpatialConnection = NewObject<USpatialWorkerConnection>(); | |||
SpatialConnection = NewObject<USpatialWorkerConnection>(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to make the GameInstance the outer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always explicitly add outers to highlight who is supposed to be owning the object. Seems like that's not the case elsewhere in the codebase though so happy to change
|
||
void USpatialGameInstance::Shutdown() | ||
{ | ||
auto World = GetWorld(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto World = GetWorld(); | |
UWorld* World = GetWorld(); |
void USpatialGameInstance::Shutdown() | ||
{ | ||
auto World = GetWorld(); | ||
if (World && SpatialConnection->IsConnected()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (World && SpatialConnection->IsConnected()) | |
if (World != nullptr && SpatialConnection->IsConnected()) |
@@ -2,6 +2,7 @@ | |||
|
|||
#include "Interop/Connection/SpatialWorkerConnection.h" | |||
|
|||
#include "EngineClasses//SpatialNetDriver.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include "EngineClasses//SpatialNetDriver.h" | |
#include "EngineClasses/SpatialNetDriver.h" |
@Vatyx after talking with @m-samiec, i've decided to leave this logic as is for now and have raised https://improbableio.atlassian.net/browse/UNR-962 for the next bit of work |
SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialWorkerConnection.cpp
Outdated
Show resolved
Hide resolved
SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialWorkerConnection.cpp
Show resolved
Hide resolved
@@ -67,7 +67,8 @@ bool USpatialGameInstance::HasSpatialNetDriver() const | |||
|
|||
void USpatialGameInstance::CreateNewSpatialWorkerConnection() | |||
{ | |||
SpatialConnection = NewObject<USpatialWorkerConnection>(); | |||
SpatialConnection = NewObject<USpatialWorkerConnection>(this); | |||
SpatialConnection->Init(GetWorld()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this going to be null at the point of initilisation for StartPlayInEditorGameInstance and StartGameInstance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean World
will be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I've seen, we always have a World
at this point
bIsConnected = false; | ||
|
||
Worker_OpList* OpList = Worker_Connection_GetOpList(WorkerConnection, 0); | ||
for (int i = 0; i < static_cast<int>(OpList->op_count); i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other place we iterate over the OpList, we use a size_t as the type for i
. Could we do the same here just to be consistent?
// TODO: Move SpatialConnection ownership to NetDriver | ||
friend class USpatialNetDriver; | ||
UPROPERTY() | ||
USpatialWorkerConnection* SpatialConnection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to break server travel in the deployments right? I'm not sure we want to do this at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if ownership of SpatialConnection
was moved to the NetDriver that would break ServerTravel
I think - how to support that would have to be part of a bigger discussion. For now, this shouldn't break anything
Hey @padhansell, I wanted to use this, but I hit an issue (might be related to the comment from @joshuahuburn above): I don't see how to access these new events in the following way;
But my problem is that the NetDriver is nullptr on the client at this stage (I call OnPostStart() at the end of StartPlayInEditorGameInstance and StartGameInstance. On the server the NetDriver is set during StartGameInstance, and on the client I can wait until LoadCompleted where it is set... but all this is a bit cumbersome. |
SpatialGDK/Source/SpatialGDK/Private/Interop/Connection/SpatialWorkerConnection.cpp
Outdated
Show resolved
Hide resolved
Co-Authored-By: padhansell <[email protected]>
…github.com/spatialos/UnrealGDK into feature/UNR-925-exposing-connection-events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, could you also please add a release note
Thanks for flagging this up @DW-Sebastien. You're right that it's not an ideal flow - once connection handling has been refactored, we'll be able to expose this same functionality through core engine delegates/virtual calls and avoid this altogether |
Co-Authored-By: padhansell <[email protected]>
* Moving events to NetDriver * Adding disconnection callback * Tidying up * Adding comments * Adding additional check for when Spatial networking is disabled * Addressing review comments * Adding getter for NetDriver * Adding TODO comment * Adding missing declaration * Review feedback Co-Authored-By: padhansell <[email protected]> * Changing iterator type * Remove whitespace Co-Authored-By: padhansell <[email protected]> * Update SpatialReceiver.h * Including World * Changing World access * Adding GEngine check
Description
This PR exposes connection events to the user through the
USpatialNetDriver
(OnConnected
,OnDisconnected
,OnConnectionFailure
). It also makes theUSpatialWorkerConnection
private in order to better encapsulate it and prevent people from relying on its availability - after discussing with @joshuahuburn and @improbable-valentyn, we'd like to move ownership of this in to theNetDriver
down the line anyway.Also note that the existing delegates have been converted to events so that they cannot be invoked outside of the
NetDriver
Tests
This was tested manually in the editor by going through these cases:
Documentation
In-code comments in
USpatialNetDriver
Release note
Feature: Exposed SpatialOS connection events in
USpatialNetDriver