So I’m using netcode for gameobjects along with relay service to make a multiplayer game (this is my first time btw). But when connecting with the client I somehow get an error saying Bad Request
Here’s the code:
public struct RelayJoinData
{
public string JoinCode;
public string IPv4Address;
public ushort Port;
public Guid AllocationID;
public byte[] AllocationIDBytes;
public byte[] ConnectionData;
public byte[] Key;
public byte[] HostConnectionData;
}
public async Task<RelayJoinData> JoinGame(string joinCode)
{
//Initialize the Unity Services engine
await UnityServices.InitializeAsync();
//Always autheticate your users beforehand
if (!AuthenticationService.Instance.IsSignedIn)
{
//If not already logged, log the user in
await AuthenticationService.Instance.SignInAnonymouslyAsync();
}
JoinAllocation joinAllocation = await Relay.Instance.JoinAllocationAsync(joinCode);
RelayJoinData data = new RelayJoinData
{
Key = joinAllocation.Key,
Port = (ushort)joinAllocation.RelayServer.Port,
AllocationID = joinAllocation.AllocationId,
AllocationIDBytes = joinAllocation.AllocationIdBytes,
ConnectionData = joinAllocation.ConnectionData,
HostConnectionData = joinAllocation.HostConnectionData,
IPv4Address = joinAllocation.RelayServer.IpV4,
JoinCode = joinCode
};
Transport.SetRelayServerData(data.IPv4Address, data.Port, data.AllocationIDBytes, data.Key, data.ConnectionData, data.HostConnectionData);
return data;
}
I tracked the error down and it seems this line is the cause of the error
JoinAllocation joinAllocation = await Relay.Instance.JoinAllocationAsync(joinCode);
However, if I change the input for JoinAllocationAsync to a fixed string (e.g: “WJBPKB”), it returns error 404 Not Found
Error: HttpException1: HTTP/1.1 400 Bad Request Unity.Services.Relay.Http.ResponseHandler.HandleAsyncResponse (Unity.Services.Relay.Http.HttpClientResponse response, System.Collections.Generic.Dictionary
2[TKey,TValue] statusCodeToTypeMap) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/Http/ResponseHandler.cs:103)
Unity.Services.Relay.Http.ResponseHandler.HandleAsyncResponse[T] (Unity.Services.Relay.Http.HttpClientResponse response, System.Collections.Generic.Dictionary`2[TKey,TValue] statusCodeToTypeMap) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/Http/ResponseHandler.cs:186)
Unity.Services.Relay.Apis.Allocations.AllocationsApiClient.JoinRelayAsync (Unity.Services.Relay.Allocations.JoinRelayRequest request, Unity.Services.Relay.Configuration operationConfiguration) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/Apis/AllocationsApi.cs:188)
Unity.Services.Relay.WrappedRelayService.JoinAllocationAsync (System.String joinCode) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/SDK/WrappedRelayService.cs:144)
Rethrow as RelayServiceException: Bad Request: invalid request schema or decoding failure
Unity.Services.Relay.WrappedRelayService.JoinAllocationAsync (System.String joinCode) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/SDK/WrappedRelayService.cs:150)
RelayManager.JoinGame (System.String joinCode) (at Assets/Scripts/RelayManager.cs:108)
UIManager.b__9_1 () (at Assets/Scripts/UIManager.cs:41)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at :0)
UnityEngine.UnitySynchronizationContext.Exec () (at :0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at :0)
Anyone know how to fix this error. This is the first time I’ve gotten this and I’m kind of confused