-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Can be called in cases with an actor owner (e.g. game mode) and cases with a non-actor owner (e.g. game instance). - In non-actor owner case, connect needs to be handled manually since the component cannot be registered
- Loading branch information
Showing
7 changed files
with
138 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2019-current Getnamo. All Rights Reserved | ||
|
||
#include "SocketIOFunctionLibrary.h" | ||
#include "LambdaRunnable.h" | ||
#include "Engine/Engine.h" | ||
|
||
USocketIOClientComponent* USocketIOFunctionLibrary::ConstructSocketIOComponent(UObject* WorldContextObject) | ||
{ | ||
USocketIOClientComponent* SpawnedComponent = NewObject<USocketIOClientComponent>(WorldContextObject, TEXT("SocketIOClientComponent")); | ||
|
||
if (SpawnedComponent) | ||
{ | ||
//Check if we got spawned by an object with an owner context (e.g. game mode) or not (e.g. game instance) | ||
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull); | ||
AActor* MyOwner = SpawnedComponent->GetOwner(); | ||
bool bOwnerHasValidWorld = (MyOwner ? MyOwner->GetWorld() : nullptr) != nullptr; | ||
|
||
SpawnedComponent->StaticInitialization(WorldContextObject, bOwnerHasValidWorld); | ||
|
||
//Register component if it was spawned by world owning context object, e.g. game mode | ||
if (bOwnerHasValidWorld) | ||
{ | ||
//Delay by 1 tick so that we can adjust bShouldAutoConnect/etc | ||
FLambdaRunnable::RunShortLambdaOnGameThread([SpawnedComponent]() | ||
{ | ||
if (SpawnedComponent->IsValidLowLevel()) | ||
{ | ||
SpawnedComponent->RegisterComponent(); | ||
} | ||
}); | ||
} | ||
|
||
//Otherwise we don't need to register our component for the networking logic to work. | ||
} | ||
return SpawnedComponent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2019-current Getnamo. All Rights Reserved | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "Kismet/BlueprintFunctionLibrary.h" | ||
#include "SocketIOClientComponent.h" | ||
#include "SocketIOFunctionLibrary.generated.h" | ||
|
||
/** | ||
* Static spawning support library | ||
*/ | ||
UCLASS() | ||
class SOCKETIOCLIENT_API USocketIOFunctionLibrary : public UBlueprintFunctionLibrary | ||
{ | ||
GENERATED_BODY() | ||
|
||
/** Static function to spawn a component that doesn't attach */ | ||
UFUNCTION(BlueprintCallable, Category = "SocketIO Client Static", meta = (WorldContext = "WorldContextObject")) | ||
static USocketIOClientComponent* ConstructSocketIOComponent(UObject* WorldContextObject); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters