Im trying to implement steam multiplayer to my game and im having an issue with player spawning.
Currently I can create and host lobby and other players can join, but when i spawn player its spawned only on that client. Im using player input manager for player spawning.
Here is all i have right now:
using UnityEngine;
using Mirror;
using Steamworks;
public class SteamLobby : MonoBehaviour
{
protected Callback<LobbyCreated_t> LobbyCreated;
protected Callback<GameLobbyJoinRequested_t> JoinRequest;
protected Callback<LobbyEnter_t> LobbyEntered;
public ulong CurrentLobbyID;
private const string HostAdressKey = "HostAddress";
private CustomNetworkManager manager;
private void Start()
{
if (!SteamManager.Initialized) { return; }
manager = GetComponent<CustomNetworkManager>();
LobbyCreated = Callback<LobbyCreated_t>.Create(OnLobbyCreated);
JoinRequest = Callback<GameLobbyJoinRequested_t>.Create(OnJoinRequest);
LobbyEntered = Callback<LobbyEnter_t>.Create(OnLobbyEntered);
}
public void HostLobby()
{
SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypeFriendsOnly, manager.maxConnections);
manager.StartHost();
manager.ServerChangeScene("LobbyRoom");
}
private void OnLobbyCreated(LobbyCreated_t callback)
{
if (callback.m_eResult != EResult.k_EResultOK) { return; }
Debug.Log("Lobby created succesfully");
SteamMatchmaking.SetLobbyData(new CSteamID(callback.m_ulSteamIDLobby), HostAdressKey, SteamUser.GetSteamID().ToString());
}
private void OnJoinRequest(GameLobbyJoinRequested_t callback)
{
Debug.Log("Request to join lobby");
SteamMatchmaking.JoinLobby(callback.m_steamIDLobby);
}
private void OnLobbyEntered(LobbyEnter_t callback)
{
CurrentLobbyID = callback.m_ulSteamIDLobby;
if(NetworkServer.active) { return; }
manager.networkAddress = SteamMatchmaking.GetLobbyData(new CSteamID(callback.m_ulSteamIDLobby), HostAdressKey);
manager.StartClient();
}
}
How can i sync object spawn, or should i completely remake player spawn. If u know any good source or some documentation for steam multiplayer could u please share, so i can learn how to implement it.
realsrbic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.