Ich versuche, Multiplayer zum Spiel in UE5.5 und VS2022 V17.12.3 mit C ++ zu verleihen. Ich kann eine Sitzung erstellen und zerstören, aber wenn ich versuche, eine Sitzung zu finden, erhalte ich Fehler beim Ausgabe von Protokoll: "Suchergebnis ist Null". (UE_LOG in Zeile 98 in MultiplayerWidget :: OnfindSessionCompletEd ()) Ich mache 2 Instanzen auf demselben PC
etwas, das mir etwas fehlt, also funktioniert es nicht ??? Danke für alle Antworten < /p>
Code: < /p>
CPP -Datei < /p>
// Fill out your copyright notice in the Description page of Project Settings.
#include "MultiplayerWidget.h"
bool UMultiplayerWidget::Initialize()
{
Super::Initialize();
EditableTextBox_369->OnTextChanged.AddDynamic(this, &UMultiplayerWidget::GetMaxPlayers); //Přidává funkci GetMaxPlayers do callu OnTextChanged
CreateSessionButton->OnClicked.AddDynamic(this, &UMultiplayerWidget::CreateSession); //Přidává funkci CreateSession do callu OnClicked
FindSessionButton->OnClicked.AddDynamic(this, &UMultiplayerWidget::FindJoinSession); //Přidává funkci FindJoinSession do callu OnClicked
DestroySessionButton->OnClicked.AddDynamic(this, &UMultiplayerWidget::DestroySession); //Přidává funkci FindJoinSession do callu OnClicked
return true;
}
//Vytvoří session snad :(
void UMultiplayerWidget::CreateSession()
{
UE_LOG(LogTemp, Warning, TEXT("Creating session")); //vypisuje do konzole Creating session
IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get(); // získá subsystem
if (OnlineSubsystem) //Kontroluje zda se získal subsystem
{
IOnlineSessionPtr SessionPtrRef = OnlineSubsystem->GetSessionInterface(); //Získá rozhraní subsystému
if (SessionPtrRef)
{
FOnlineSessionSettings SessionInfo; //settings pro session
SessionInfo.bIsDedicated = false;
SessionInfo.bAllowInvites = true;
SessionInfo.bIsLANMatch = true;
SessionInfo.NumPublicConnections = maxPlayers;
SessionInfo.bUseLobbiesIfAvailable = false;
SessionInfo.bUsesPresence = false;
SessionInfo.bShouldAdvertise = true;
SessionInfo.Set(TEXT("SEARCH_SESSION"), FString("Test"), EOnlineDataAdvertisementType::ViaOnlineService);
SessionPtrRef->OnCreateSessionCompleteDelegates.AddUObject(this, &UMultiplayerWidget::OnCreatedSessionCompleted); //nastavení, že po dkončení vytváření session se spustí funce created s hodnotou true||false podle toho zda se session vytvořila úspěšně
SessionPtrRef->CreateSession(0, FName("MainSession"), SessionInfo);
}
}
}
//Kontrolní funkce zda se vytvořila session nebo ne
void UMultiplayerWidget::OnCreatedSessionCompleted(FName sessionName, bool succesful) {
FString sessionNamestring = sessionName.ToString();
UE_LOG(LogTemp, Warning, TEXT("Was session: %s created successfully?: %s"), *sessionNamestring, (succesful ? TEXT("true") : TEXT("false"))); //vypisuje do konzole zda se session vytvořila či ne
}
//Získá číslo z EditableTextBox_369, to se poté použije jako maximální hranice pro hráčů na session
void UMultiplayerWidget::GetMaxPlayers(const FText& ftext)
{
FString text = ftext.ToString(); //FText na FString
maxPlayers = FCString::Atoi(*text); //Convert FString na int
}
//Najidí a připojení se k session
void UMultiplayerWidget::FindJoinSession() {
IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get(); // získá subsystem
if (OnlineSubsystem) //Kontroluje zda se získal subsystem
{
IOnlineSessionPtr SessionPtrRef = OnlineSubsystem->GetSessionInterface(); //Získá rozhraní subsystému
if (SessionPtrRef) //Kontroluje zda se získal rozhraní
{
sessionSearch = MakeShareable(new FOnlineSessionSearch());
sessionSearch->QuerySettings.Set(TEXT("SEARCH_SESSION"), true, EOnlineComparisonOp::Equals);
sessionSearch->MaxSearchResults = 20;
sessionSearch->bIsLanQuery = true;
SessionPtrRef->OnFindSessionsCompleteDelegates.AddUObject(this, &UMultiplayerWidget::OnFindSessionCompleted);
SessionPtrRef->FindSessions(0, sessionSearch.ToSharedRef());
}
}
}
void UMultiplayerWidget::OnFindSessionCompleted(bool successful) {
if (successful) {
UE_LOG(LogTemp, Warning, TEXT("Finding session was succesful"));
IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get(); // získá subsystem
if (OnlineSubsystem) //Kontroluje zda se získal subsystem
{
IOnlineSessionPtr SessionPtrRef = OnlineSubsystem->GetSessionInterface(); //Získá rozhraní subsystému
if (SessionPtrRef) //Kontroluje zda se získal rozhraní
{
if (sessionSearch->SearchResults.Num() > 0 && sessionSearch->SearchResults[0].IsValid()) {
SessionPtrRef->OnJoinSessionCompleteDelegates.AddUObject(this, &UMultiplayerWidget::OnJoinSessionCompleted);
SessionPtrRef->JoinSession(0, FName("MainSession"), sessionSearch->SearchResults[0]);
}
else {
UE_LOG(LogTemp, Error, TEXT("search result is zero"));
}
}
}
}
}
void UMultiplayerWidget::OnJoinSessionCompleted(FName sessionName, EOnJoinSessionCompleteResult::Type result) {
if (result == EOnJoinSessionCompleteResult::Success) {
if (APlayerController* playerControllerRef = UGameplayStatics::GetPlayerController(GetWorld(), 0)) {
FString JoinAddress;
IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get();
if (OnlineSubsystem) {
IOnlineSessionPtr SessionPtrRef = OnlineSubsystem->GetSessionInterface();
if (SessionPtrRef) {
if (SessionPtrRef->GetResolvedConnectString(FName("MainSession"), JoinAddress)) {
UE_LOG(LogTemp, Warning, TEXT("Address: %s"), *JoinAddress);
playerControllerRef->ClientTravel(JoinAddress, ETravelType::TRAVEL_Absolute);
}
}
}
}
}
}
void UMultiplayerWidget::DestroySession() {
IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get(); // získá subsystem
if (OnlineSubsystem) //Kontroluje zda se získal subsystem
{
IOnlineSessionPtr SessionPtrRef = OnlineSubsystem->GetSessionInterface(); //Získá rozhraní subsystému
if (SessionPtrRef) //Kontroluje zda se získal rozhraní
{
SessionPtrRef->OnDestroySessionCompleteDelegates.AddUObject(this, &UMultiplayerWidget::OnDestroyedSessionCompleted);
SessionPtrRef->DestroySession(FName("MainSession"));
}
}
}
void UMultiplayerWidget::OnDestroyedSessionCompleted(FName sessionName, bool succesful) {
FString sessionNamestring = sessionName.ToString();
UE_LOG(LogTemp, Warning, TEXT("Was session: %s destroyed successfully?: %s"), *sessionNamestring, (succesful ? TEXT("true") : TEXT("false"))); //vypisuje do konzole zda se session zničila či ne
}
< /code>
Header -Datei < /p>
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Components/Button.h"
#include "Components/EditableTextBox.h"
#include "Components/CheckBox.h"
#include "OnlineSubsystem.h"
#include "OnlineSessionSettings.h"
#include "Interfaces/OnlineSessionInterface.h"
#include "OnlineSubsystemUtils.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/Player.h"
#include "MultiplayerWidget.generated.h"
/**
*
*/
UCLASS()
class NOXVIRIDUS_API UMultiplayerWidget : public UUserWidget
{
GENERATED_BODY()
virtual bool Initialize();
//Deklarace UI prvků
UPROPERTY(meta = (BindWidget))
class UButton* CreateSessionButton;
UPROPERTY(meta = (BindWidget))
UButton* FindSessionButton;
UPROPERTY(meta = (BindWidget))
UButton* DestroySessionButton;
UPROPERTY(meta = (BindWidget))
class UEditableTextBox* EditableTextBox_369;
UPROPERTY(meta = (BindWidget))
class UCheckBox* CheckBox_146;
//Deklarace funkcí
UFUNCTION()
void CreateSession();
UFUNCTION()
void OnCreatedSessionCompleted(FName sessionName, bool successful);
UFUNCTION()
void FindJoinSession();
UFUNCTION()
void OnFindSessionCompleted(bool successful);
void OnJoinSessionCompleted(FName sessionName, EOnJoinSessionCompleteResult::Type result);
UFUNCTION()
void DestroySession();
UFUNCTION()
void OnDestroyedSessionCompleted(FName sessionName, bool successful);
UFUNCTION()
void GetMaxPlayers(const FText& ftext);
private:
int maxPlayers;
TSharedPtr sessionSearch;
};
Ich versuche, Multiplayer zum Spiel in UE5.5 und VS2022 V17.12.3 mit C ++ zu verleihen. Ich kann eine Sitzung erstellen und zerstören, aber wenn ich versuche, eine Sitzung zu finden, erhalte ich Fehler beim Ausgabe von Protokoll: "Suchergebnis ist Null". (UE_LOG in Zeile 98 in MultiplayerWidget :: OnfindSessionCompletEd ()) Ich mache 2 Instanzen auf demselben PC etwas, das mir etwas fehlt, also funktioniert es nicht ??? Danke für alle Antworten < /p> Code: < /p> CPP -Datei < /p> [code]// Fill out your copyright notice in the Description page of Project Settings.
EditableTextBox_369->OnTextChanged.AddDynamic(this, &UMultiplayerWidget::GetMaxPlayers); //Přidává funkci GetMaxPlayers do callu OnTextChanged
CreateSessionButton->OnClicked.AddDynamic(this, &UMultiplayerWidget::CreateSession); //Přidává funkci CreateSession do callu OnClicked FindSessionButton->OnClicked.AddDynamic(this, &UMultiplayerWidget::FindJoinSession); //Přidává funkci FindJoinSession do callu OnClicked DestroySessionButton->OnClicked.AddDynamic(this, &UMultiplayerWidget::DestroySession); //Přidává funkci FindJoinSession do callu OnClicked
return true; }
//Vytvoří session snad :( void UMultiplayerWidget::CreateSession() { UE_LOG(LogTemp, Warning, TEXT("Creating session")); //vypisuje do konzole Creating session
if (OnlineSubsystem) //Kontroluje zda se získal subsystem { IOnlineSessionPtr SessionPtrRef = OnlineSubsystem->GetSessionInterface(); //Získá rozhraní subsystému if (SessionPtrRef) { FOnlineSessionSettings SessionInfo; //settings pro session SessionInfo.bIsDedicated = false; SessionInfo.bAllowInvites = true; SessionInfo.bIsLANMatch = true; SessionInfo.NumPublicConnections = maxPlayers; SessionInfo.bUseLobbiesIfAvailable = false; SessionInfo.bUsesPresence = false; SessionInfo.bShouldAdvertise = true; SessionInfo.Set(TEXT("SEARCH_SESSION"), FString("Test"), EOnlineDataAdvertisementType::ViaOnlineService);
SessionPtrRef->OnCreateSessionCompleteDelegates.AddUObject(this, &UMultiplayerWidget::OnCreatedSessionCompleted); //nastavení, že po dkončení vytváření session se spustí funce created s hodnotou true||false podle toho zda se session vytvořila úspěšně
//Kontrolní funkce zda se vytvořila session nebo ne void UMultiplayerWidget::OnCreatedSessionCompleted(FName sessionName, bool succesful) { FString sessionNamestring = sessionName.ToString(); UE_LOG(LogTemp, Warning, TEXT("Was session: %s created successfully?: %s"), *sessionNamestring, (succesful ? TEXT("true") : TEXT("false"))); //vypisuje do konzole zda se session vytvořila či ne } //Získá číslo z EditableTextBox_369, to se poté použije jako maximální hranice pro hráčů na session void UMultiplayerWidget::GetMaxPlayers(const FText& ftext) { FString text = ftext.ToString(); //FText na FString maxPlayers = FCString::Atoi(*text); //Convert FString na int }
//Najidí a připojení se k session void UMultiplayerWidget::FindJoinSession() { IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get(); // získá subsystem
if (OnlineSubsystem) //Kontroluje zda se získal subsystem { IOnlineSessionPtr SessionPtrRef = OnlineSubsystem->GetSessionInterface(); //Získá rozhraní subsystému if (SessionPtrRef) //Kontroluje zda se získal rozhraní { sessionSearch = MakeShareable(new FOnlineSessionSearch()); sessionSearch->QuerySettings.Set(TEXT("SEARCH_SESSION"), true, EOnlineComparisonOp::Equals); sessionSearch->MaxSearchResults = 20; sessionSearch->bIsLanQuery = true;
if (OnlineSubsystem) //Kontroluje zda se získal subsystem { IOnlineSessionPtr SessionPtrRef = OnlineSubsystem->GetSessionInterface(); //Získá rozhraní subsystému if (SessionPtrRef) //Kontroluje zda se získal rozhraní { SessionPtrRef->OnDestroySessionCompleteDelegates.AddUObject(this, &UMultiplayerWidget::OnDestroyedSessionCompleted); SessionPtrRef->DestroySession(FName("MainSession")); } } } void UMultiplayerWidget::OnDestroyedSessionCompleted(FName sessionName, bool succesful) { FString sessionNamestring = sessionName.ToString(); UE_LOG(LogTemp, Warning, TEXT("Was session: %s destroyed successfully?: %s"), *sessionNamestring, (succesful ? TEXT("true") : TEXT("false"))); //vypisuje do konzole zda se session zničila či ne } < /code> Header -Datei < /p> // Fill out your copyright notice in the Description page of Project Settings.
Ich habe gerade das UE5(5.5) C++-Projekt mit VS2022 gestartet, aber es gibt ein Problem.
Alle Klassen, Variablen und Funktionsname sind alle weiß und können nicht umbenannt werden. Es kann nicht zur...
Ich habe ein Projekt Unreal Engine 5.1 gemacht, bei dem ich dieses Tutorial verwendet habe, um Charakterbewegungen und Animationen einzurichten. Ich benutze diesen Vermögenswert als Spieler. Mein...
Ich habe ein Projekt Unreal Engine 5.1 gemacht, bei dem ich dieses Tutorial verwendet habe, um Charakterbewegungen und Animationen einzurichten. Ich benutze diesen Vermögenswert als Spieler. Mein...
Ich habe ein Projekt Unreal Engine 5.1 gemacht, bei dem ich dieses Tutorial verwendet habe, um Charakterbewegungen und Animationen einzurichten. Ich benutze diesen Vermögenswert als Spieler. Mein...
Ich versuche, mein statisches LIB -Projekt von VS 2017 auf VS 2022 zu verbessern. In meinem Projekt habe ich nur eine Klasse.
class MyClass
{
private:
int count;
static int data;
public:...