Important additional comments: 👉🏽 The final code is in the video description 👉🏽 In the restart part staring at 3:00:00, I've been missing a change in the AllPlayerDataManager. Please overwrite the "OnNetworkDespawn" method with the following: public void OnDisable() { if (IsServer) { allPlayerData.Clear(); NetworkManager.Singleton.OnClientConnectedCallback -= AddNewClientToList; } BulletData.OnHitPlayer -= BulletDataOnOnHitPlayer; KillPlayer.OnKillPlayer -= KillPlayerOnOnKillPlayer; RestartGame.OnRestartGame -= RestartGameOnOnRestartGame; } More concisely, we need to change the OnNetworkDespawn into OnDisable (no overwrite anymore) and need to clear our Network list when we are the Server. Thank you, @nomisnibor for pointing out the issue!
@mikedoroshenko8816 ай бұрын
You inspired me to learn AR and I've created my first AR experience with your help! Thank you!!!
@AliveStudios_6 ай бұрын
Hey Mike, first of all thanks a bunch, I'm really glad to hear that! The persistant object tutorial is actually using ARDK 3.1, so the setup is pretty much the same :)
@vidhuvidhuxen2626 ай бұрын
It's very very great bro. I was just getting started with Lightship + Unity. It is a great timing. I am going to start watching it. Thank you so much for bringing this much value for XR community.
@AliveStudios_6 ай бұрын
Thank you for your kind words :) Hope the tutorial is useful for you
@vidhuvidhuxen2626 ай бұрын
@@AliveStudios_ ❤
@411vids4 ай бұрын
Thanks for sharing your skills. Great video!
@fx_nodeАй бұрын
I would really like some one to do this for the quest headset
@nomisnibor6 ай бұрын
Really amazing tutorial, you are amazing man! Congratulations on your huge effort!!!! I finally managed to complete the tutorial and got two issues so far: if I click on kill until killing my player and choose to quit then, impossible to create a room anymore. And on AR mobile phone only, sometime I can create a room, sometimes I can't... Also, I have a red line showing, I wonder why...
@AliveStudios_6 ай бұрын
Hey man, really glad you like it and could make it all the way through. Indeed the issue with not being able to create a room might be, because there is no or weak internet connection. I had this issue in editor when working in the train and as soon as my hotspot reconnected, I could create a room again. Solution here would be to create a script that checks the internet connection and if there is none, greys out the buttons. Besides that, as already stated, you can just send me your project files and I will check on these problems, if you want :)
@nomisnibor6 ай бұрын
@@AliveStudios_ Great man, thank you so much, I will prepare it for you. Regarding the connection, it is strange as I am using a good wifi connection all the time... Also, do you face the same issue, when you quit the game after being killed? I can no longer spawn the payer.
@AliveStudios_6 ай бұрын
@@nomisnibor Hey man I just checked the code again and you are right, I actually missed a little but important change when implementing the restart logic. In your AllPlayerDataManager, change the override OnNetworkDespawn method with this: public void OnDisable() { if (IsServer) { allPlayerData.Clear(); NetworkManager.Singleton.OnClientConnectedCallback -= AddNewClientToList; } BulletData.OnHitPlayer -= BulletDataOnOnHitPlayer; KillPlayer.OnKillPlayer -= KillPlayerOnOnKillPlayer; RestartGame.OnRestartGame -= RestartGameOnOnRestartGame; } (So basically, instead of OnNetworkDespawn -> On Disable and add the allPlayerData.Clear() in a if(IsServer) Statement Can you tell me if that worked for you?
@nomisnibor6 ай бұрын
@@AliveStudios_ Hey man, bravo. Nice modifications. Unfortunately, for me, now this 'new' issue after dying. I can go back to the screen to create a new room which I can do but I can no longer start it. Would you know why?
@AliveStudios_5 ай бұрын
Sorry for the late answer! Did you try any debugging or do you get any error message?
@yaseenbasha158812 күн бұрын
Really unique and good tutorial!! But i am having an issue at the 50 min mark where there all of a sudden a playerdata game object was added it wasnt there before and i am not able to stop multiple spawns of the character. would appreciate your help
@AliveStudios_10 күн бұрын
Hi mate , did you already try to compare your code with the final code in the video description? I am not quite sure if I get your question right, does it mean that the creation of the playerdata does not work correctly for you or does the player data get created correctly but you are still able to spawn the character multiple times?
@akosinelz32776 ай бұрын
When you will create lightship maps guide?
@AliveStudios_5 ай бұрын
I have it on my list but can't promise anything :)
@DotsAndDashesInteractives4 ай бұрын
Hey man, the tutorial is really helpful, i have one question is it possible to deploy this game to webgl?
@AliveStudios_4 ай бұрын
Hey mate, currently sadly not ,but that would be awesome :)
@Sylar395Ай бұрын
hey, thank you for this tutorial, but i get problems around 14.20 when i start client it wont conect it says this Trying to send ClientConnectedMessage to client 0 which is not in a connected state. UnityEngine.Debug:LogWarning (object) do you know what to do?
@AliveStudios_28 күн бұрын
Hi mate, make sure you’re calling NetworkManager.StartClient() after the server has been initialized and is ready to accept connections. If the client attempts to connect too early, it could result in this error. Ensure that the server has successfully started before the client attempts to connect. You can verify this by checking if NetworkManager.Singleton.IsServer is true on the server instance. Debug.Log("IsServer: " + NetworkManager.Singleton.IsServer); Debug.Log("IsClient: " + NetworkManager.Singleton.IsClient); Debug.Log("IsConnected: " + NetworkManager.Singleton.IsConnectedClient);
@metehansirin63684 ай бұрын
Hello can I ask a question? Is it possible to make a this kind of game with using Playmaker and Lightship? I'm just starting to learn Unity and I was wondering if I could use Playmaker instead of coding to make AR games with Lightship.
@AliveStudios_4 ай бұрын
Hey mate, I am not quite sure about that :) please let me know if you figure it out
@nischalnaik32975 ай бұрын
hello , can you also share the final apk for android please
@LongPham-ud7zk28 күн бұрын
Can you help me, i don't know why i cant't Instantiate bullet
@AliveStudios_28 күн бұрын
Hi mate, do you get any error message?
@LongPham-ud7zk28 күн бұрын
I fix it already, thank you 😂
@LongPham-ud7zk28 күн бұрын
@@AliveStudios_i don’t know why when i take the photo but it don’t spawn character for me to play
@nomisnibor6 ай бұрын
If anyone has done this tutorial, it would be amazing to share the scripts. I have must have done something wrong somewhere but impossible to find the issue...
@AliveStudios_6 ай бұрын
You can find the scripts here : github.com/Alive-hub/AR-Multiplayer-Lightship/tree/main/Scripts :)
@nomisnibor6 ай бұрын
@@AliveStudios_ Awesome, thank you so much!!!
@edwinsunny7679Ай бұрын
bro i have many errors i don't know how to correct it
@AliveStudios_Ай бұрын
What kind of errors do you have :) ?
@edwinsunny7679Ай бұрын
@@AliveStudios_when i click start room button 1 character appears also when i touch the plane another character appears if i click again nothing happens but 2 characters is present . these are the errors i am facing
@migeee97185 ай бұрын
Thank you mate, your tutorial is really helpful~ I've walked through almost all the course but I got error message when I tried to create room and start game after altering the NonAR transport to AR transport ( at 3:48:32) . Can you help me plz :) The error message is as following: [Netcode] Host is shutting down due to network transport start failure of LightshipNetcodeTransport! UnityEngine.Debug:LogError (object) Unity.Netcode.NetworkLog:LogError (string) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.0/Runtime/Logging/NetworkLog.cs:34) Unity.Netcode.NetworkConnectionManager:TransportFailureEventHandler (bool) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.0/Runtime/Connection/NetworkConnectionManager.cs:388) Unity.Netcode.NetworkManager:StartHost () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.0/Runtime/Core/NetworkManager.cs:891) StartGameAR:StartGame () (at Assets/Scripts/Game/StartGameAR.cs:76) UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)
@AliveStudios_5 ай бұрын
Do you use the onscreen buttons that we created, instead of the start host / client in the inspector window :) ?
@migeee97185 ай бұрын
@@AliveStudios_ yes, I read the other comment, it looks similar but it's not the same issue. I didn't use the client to test, the error occurred when I only tested the host to create the room. Is it possible that there is an issue with my network? TT
@AliveStudios_5 ай бұрын
@@migeee9718 Generally yes, I was testing this while I was sitting in a train and had bad wifi and it didn't work either. Generally though what you can try too is to delete the library folder in the project folder and let the project rebuild itself. Make sure to have good internet and that the Transport Layer / System is Lightship and only use the on screen buttons. If that does not help, you can too send me your project via google drive and I'll check it out :)
@HingHingZoneZone5 ай бұрын
@@migeee9718 Hi mate~ You only need to click the "play" mode then everything on the game screen . If we click "Start Host" or "Start Client" will get that Error. Because the AR Multiplayer GAME state doesn't need hosting for this. Hope it will help for you~ Good Luck :)
@HingHingZoneZone5 ай бұрын
Hello Toby~ Thanks for your tutorial & I had followed the whole project. I think my project everything is fine but I get one error I cannot solve. Do you have any idea why? How can I solve this Lightship transport network Error on below? ( I'm building for Android system) Hope you can help me out~ Thank you~ On Server Side: [Netcode] Host is shutting down due to network transport start failure of LightshipNetcodeTransport! UnityEngine.Debug:LogError (object) On Client Side: [Netcode] Client is shutting down due to network transport start failure of LightshipNetcodeTransport! UnityEngine.Debug:LogError (object)
@AliveStudios_5 ай бұрын
Hey mate, in what context does this error appear and in which script ?
@HingHingZoneZone5 ай бұрын
@@AliveStudios_ Hi Toby~ It's should appear after (03:25:07 Adding AR) in my case. Because I still can continue the project without Multiplayer, so I just finished all & check what's the problem All my script already replace from your files, everything is fine but cannot test with network Multiplayer. When I Play the game is fine. But when I click Start Host & Start Client, It show that Error.
@AliveStudios_5 ай бұрын
@@HingHingZoneZone Got it, so you cannot use multiplayer at all? Even in non AR?
@HingHingZoneZone5 ай бұрын
@@AliveStudios_ Hi Toby~ I just check with Non AR mode, Everything is fine. My Error only with AR Lightship transport network for multiplayer
@AliveStudios_5 ай бұрын
@@HingHingZoneZone Did you make sure to use the Networkmanager AR and inside the network manager AR change the Network Transport to Lightship , like shown at 3:26:26 ?
@nomisnibor6 ай бұрын
Amazing tutorial, as usual ;P Thank you so much. I'm sorry, I have a question actually, I cannot get the Log message when added a new client and I cannot NOT add more players to the scene, I am getting these 2 error messages: (and I have set the player to the Placement Object from the Inspector PlacePlayer panel): NullReferenceException: Object reference not set to an instance of an object PlaceCharacter.SpawnPlayerServerRpc (UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, System.UInt64 callerID) (at Assets/Scripts/Placement/PlaceCharacter.cs:93) PlaceCharacter.__rpc_handler_388040609 (Unity.Netcode.NetworkBehaviour target, Unity.Netcode.FastBufferReader reader, Unity.Netcode.__RpcParams rpcParams) (at :0) Unity.Netcode.RpcMessageHelpers.Handle (Unity.Netcode.NetworkContext& context, Unity.Netcode.RpcMetadata& metadata, Unity.Netcode.FastBufferReader& payload, Unity.Netcode.__RpcParams& rpcParams) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Messaging/Messages/RpcMessages.cs:70) Rethrow as Exception: Unhandled RPC exception! UnityEngine.Debug:LogException(Exception) Unity.Netcode.RpcMessageHelpers:Handle(NetworkContext&, RpcMetadata&, FastBufferReader&, __RpcParams&) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Messaging/Messages/RpcMessages.cs:74) Unity.Netcode.ServerRpcMessage:Handle(NetworkContext&) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Messaging/Messages/RpcMessages.cs:125) Unity.Netcode.NetworkBehaviour:__endSendServerRpc(FastBufferWriter&, UInt32, ServerRpcParams, RpcDelivery) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkBehaviour.cs:90) PlaceCharacter:SpawnPlayerServerRpc(Vector3, Quaternion, UInt64) (at Assets/Scripts/Placement/PlaceCharacter.cs:87) PlaceCharacter:TouchToRay(Vector3) (at Assets/Scripts/Placement/PlaceCharacter.cs:79) PlaceCharacter:Update() (at Assets/Scripts/Placement/PlaceCharacter.cs:34) NullReferenceException: Object reference not set to an instance of an object PlaceCharacter.SpawnPlayerServerRpc (UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, System.UInt64 callerID) (at Assets/Scripts/Placement/PlaceCharacter.cs:93) PlaceCharacter.TouchToRay (UnityEngine.Vector3 touch) (at Assets/Scripts/Placement/PlaceCharacter.cs:79) PlaceCharacter.Update () (at Assets/Scripts/Placement/PlaceCharacter.cs:34)
@nomisnibor6 ай бұрын
I have done the tutorial 3 times now from scratch until 1:00:00 but I cannot see what I missed, it would be fantastic if anyone could help me to go further. Please see AllPlayerDataManager script the below: using System.Collections; using System.Collections.Generic; using UnityEngine; using Unity.Netcode; using System; public class AllPlayerDataManager : NetworkBehaviour { public static AllPlayerDataManager Instance; private NetworkList allPlayerData; private const int LIFEPOINTS = 10; private void Awake() { allPlayerData = new NetworkList(); if (Instance != null && Instance != this) { Destroy(Instance); } Instance = this; } public void AddPlacedPlayer(ulong id) { for(int i = 0; i < allPlayerData.Count; i++) { if (allPlayerData[i].clientID == id) { PlayerData newData = new PlayerData( allPlayerData[i].clientID, allPlayerData[i].score, allPlayerData[i].lifePoints, playerPlaced: true ); allPlayerData[i] = newData; } } } public bool GetHasPlacerPlaced(ulong id) { for (int i = 0; i < allPlayerData.Count; i++) { if(allPlayerData[i].clientID == id) { return allPlayerData[i].playerPlaced; } } return false; } public override void OnNetworkSpawn() { if (IsServer) { AddNewClientToList(NetworkManager.LocalClientId); } } void Start() { NetworkManager.Singleton.OnClientConnectedCallback += AddNewClientToList; } void AddNewClientToList(ulong clientID) { if(!IsServer) return; foreach (var playerData in allPlayerData) { if(playerData.clientID == clientID) return; } PlayerData newPlayerData = new PlayerData(); newPlayerData.clientID = clientID; newPlayerData.score = 0; newPlayerData.lifePoints = LIFEPOINTS; newPlayerData.playerPlaced = false; if(allPlayerData.Contains(newPlayerData)) return; allPlayerData.Add(newPlayerData); PrintAllPlayerPlayerList(); } void PrintAllPlayerPlayerList() { foreach (var playerData in allPlayerData) { Debug.Log(message: "Player ID => " + playerData.clientID + " hasPlaced " + playerData.playerPlaced + " Called by " + NetworkManager.Singleton.LocalClientId); } } }
@AliveStudios_6 ай бұрын
Hi mate, thanks a bunch for your kind words :) Did you double check that your Player has a NetworkObject component attached to it? And did you correctly create a new instance of the AllPlayerDataManager in it's awake method?
@nomisnibor6 ай бұрын
@@AliveStudios_ Thank you so much for your response, I have doubled check and I have a NetworkObject component attached to it. I have no problem adding characters from both host and client but I don't get the debugging message for seeing client details and I can always add new characters... Also, I have made this into the AllPlayerdataManager script: private void Awake() { allPlayerData = new NetworkList(); if (Instance != null && Instance != this) { Destroy(Instance); } Instance = this; } Maybe, there is an issue in my PlaceCharacter script? using System; using System.Collections; using System.Collections.Generic; using Unity.Netcode; using UnityEditor; using UnityEngine; using UnityEngine.EventSystems; public class PlaceCharacter : NetworkBehaviour { [SerializeField] private GameObject placementObject; private Camera mainCam; private void Start() { mainCam = GameObject.FindObjectOfType(); } void Update() { if (AllPlayerDataManager.Instance != default && AllPlayerDataManager.Instance.GetHasPlacerPlaced(NetworkManager.Singleton.LocalClientId)) return; #if UNITY_EDITOR if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject()) { Debug.Log(message: "UI Hit was recognized"); return; } TouchToRay(Input.mousePosition); } #endif #if UNITY_IOS || UNITY_ANDROID if (Input.touchCount > 0 && Input.touchCount < 2 && Input.GetTouch(index:0).phase == TouchPhase.Began) { Touch touch = Input.GetTouch(index:0); PointerEventData pointerData = new PointerEventData(EventSystem.current); pointerData.position = touch.position; List results = new List(); EventSystem.current.RaycastAll(pointerData, results); if (results.Count > 0) { // We hit a UI element Debug.Log(message:"We hit an UI Element"); return; } Debug.Log(message: "Touch detected, fingerId: " + touch.fingerId); // Debugging line if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { Debug.Log(message: "Is Pointer Over GOJ, No placement "); return; } TouchToRay(touch.position); } #endif } void TouchToRay(Vector3 touch) { Ray ray = mainCam.ScreenPointToRay(touch); RaycastHit hit; if (Physics.Raycast(ray ,out hit)) { Quaternion rotation = Quaternion.FromToRotation(Vector3.up, hit.normal); SpawnPlayerServerRpc(hit.point, rotation, NetworkManager.Singleton.LocalClientId); } } [ServerRpc(RequireOwnership = false)] void SpawnPlayerServerRpc(Vector3 position, Quaternion rotation, ulong callerID) { GameObject character = Instantiate(placementObject, position, rotation); NetworkObject characterNetworkObject = character.GetComponent(); characterNetworkObject.SpawnWithOwnership(callerID); AllPlayerDataManager.Instance.AddPlacedPlayer(callerID); } } Thank you so much for taking time to respond to me!
@AliveStudios_6 ай бұрын
@@nomisniborDid you already compare you script to the one in the video description? You can download them here : github.com/Alive-hub/AR-Multiplayer-Lightship/tree/main/Scripts
@AliveStudios_6 ай бұрын
@@nomisnibor For me it seems like the AddPlacedPlayer method is missing in your AllPlayerDataManager :)
@JohnnyPJR5 ай бұрын
Hi Toby, I have some questions about Unity and AR. I sent you an email, is there a better way to contact you? Thanks
@AliveStudios_5 ай бұрын
Hi John, sorry I had only now time to answer your mail :)
@AkashGameDev5 ай бұрын
Hello, followed this video multiple times and can't go past beyond the One Hour Mark as it always says this Error Message, my target platform is Android: NullReferenceException: Object reference not set to an instance of an object PlaceCharacter.SpawnPlayerServerRpc (UnityEngine.Vector3 positon, UnityEngine.Quaternion rotation, System.UInt64 callerID) (at Assets/Scripts/Placement/PlaceCharacter.cs:97) PlaceCharacter.TouchToRay (UnityEngine.Vector3 touch) (at Assets/Scripts/Placement/PlaceCharacter.cs:83) PlaceCharacter.Update () (at Assets/Scripts/Placement/PlaceCharacter.cs:38)
@AliveStudios_5 ай бұрын
Hi mate :) Did you double check your code with the one in the video description and is it identical?
@AkashGameDev5 ай бұрын
@@AliveStudios_ Yes, I did. And it is identical.
@AliveStudios_5 ай бұрын
@@AkashGameDev What happens if you debug.log all the values so , position, rotation , caller ID, placement object , characterNetworkObject AllPlayerDataManager.Instance? You could try this: [ServerRpc(RequireOwnership = false)] void SpawnPlayerServerRpc(Vector3 position, Quaternion rotation, ulong callerID) { Debug.Log($"Attempting to spawn player at position: {position} with rotation: {rotation} for callerID: {callerID}"); if (placementObject == null) { Debug.LogError("Placement object is null!"); return; } GameObject character = Instantiate(placementObject, position, rotation); if (character == null) { Debug.LogError("Failed to instantiate character!"); return; } NetworkObject characterNetworkObject = character.GetComponent(); if (characterNetworkObject == null) { Debug.LogError("Character does not have a NetworkObject component!"); return; } Debug.Log("Character instantiated and NetworkObject component retrieved."); characterNetworkObject.SpawnWithOwnership(callerID); Debug.Log("Spawned character with ownership."); if (AllPlayerDataManager.Instance == null) { Debug.LogError("AllPlayerDataManager.Instance is null!"); return; } AllPlayerDataManager.Instance.AddPlacedPlayer(callerID); Debug.Log("Player added to AllPlayerDataManager."); } then you should see what's the issue.
@AkashGameDev5 ай бұрын
@@AliveStudios_ Hello, thanks for the reply. Appreciate it. I have done the following things you have said and it showed error in this point: AllPlayerDataManager.Instance is null!
@AliveStudios_5 ай бұрын
@@AkashGameDev Ok that is great, we know the issue! Then you need to check the AllPlayerData Manager and need to make sure, to create the Instance in the Awake method like this: private void Awake() { allPlayerData = new NetworkList(); if (Instance != null && Instance != this) { Destroy(Instance); } Instance = this; } Then the null error message should go away.