Every time I reopen the Unity editor the canvas gets these ridiculous dimensions, after pressing play it stays like that for a second and then resets itself to a sensible default size, including everything under it. That means all buttons have the same default position. Any idea what it may be? Even when adding a new canvas it has these dimensions.
You are not the first to have this issue and i have tried replicating this myself multiple times and have not been successful as of yet.
Are you using the current LTS version of unity in 2022? This seems to be the common denominator and the only thing i could see that was any different from what i was using was in the game view i was using 1920 * 1080 HD rather than free aspect.
I will keep looking into this and see if i can find a solution.
I’m using 2022.3.4f1 LTS (which exact version do you use?)
Game view is Full HD 1920x1080
The problem is present on a brand new project as well so it’s possible we’re dealing with a unity bug or a problem that presented itself during installation. This is a freshly installed Unity version, my 2021 LTS version works properly.
I’m using a slightly earlier version of the LTS version in 2022.3.3f1 but i have students on Udemy that are experiencing issues with the buttons changing positions using the same version i am.
However that being said their issues is likely the canvas scaler being the culprit in that its not set to the same as the game view settings and not set to scale with screen size.
I’ve completed re-running the course to pick up any bugs that may have arisen due to the netcode package being updated this evening and i am out of the office to later on Monday/Tuesday but i will try to get some time aside to get a copy of the project and run this lecture in the same version as you to see if i recreate it again.
It could well be a unity bug in your case with it being a newer LTS version
There was a bug in the 2022.3.3f1 version which sometimes caused the canvas scaler not to work correctly and i suspect that is what is happening here.
It may pay to wait a couple of days to see if they fix the issue or if you can work around it.
I tested in the earlier versions and as you state it does not occur there.
The other students having issues with the buttons not holding their values was in this version but strangely they are not having the issue you are in the 2022.3.4f1 which leads me to believe its an install/project set up problem.
Update:
So the problem is that upon building (thus in game exe) and reloading editor the canvas dimensions get destroyed, the button/UI layout gets reset but it has some (in)consistencies one can exploit.
The host/client buttons used to be one beneath the other and anchored to the top left. Upon reset they get the same position/overlap and can no longer be used. Solution is to put the second button to the right as it seems that it only resets the vertical positioning (meaning if anchor is top left the Y coordinate will be reset to 0 so everything will be on top).
Furthermore when making the main menu later on in the course everything worked fine:
the anchor had normal centering thus the buttons wouldn’t get their positions reset - they’d keep the positions you want. I’ll update this as it seems to be a bug with how it resets anchored positions upon canvas reset
Hi,
I’ve exhausted all options and then contacted Nathan for help and we found out that 2022.3 is actually actively being avoided by people at present as its riddled with UI bugs mostly happening in the game window.
In addition to this we have found that sometimes the game window wont even register the mouse position it stays locked to 0,0,0 and also that its either not registering the clicks or the locking to 0,0,0 means the UI does not have the cursor as over the buttons so you cant press them.
Also its seemingly caused issues with aiming with a turret as again its locked to the 0,0,0 position so the turret in the course cannot rotate to where the cursor mouse position actually is.
The best bet for now is to avoid 2022.3 completely and restart the course in 2022.2 as we know this works without issue and in the future the patches we have added can be changed once 2022.3 is working and stable!
Dang, that sucks.
How smart would it be to just update it all to 2023?
I havent tested it because its currently in beta i have used 2023 for another course but using UI in world space but it did not cause any issues for me.
That being said the nature of this bug is that it happens when the project is created or when using the new input system so as we dont use the new input system in this other course i cant say if it is stable or not.
The other issue is that i dont know how compatible the packages will be with 2023 so there may be issues there that i havent tested either although it doesnt look like that have been changed that recently so they may be fine.
Its up to you if you want to give it a try as i will try to support you in either choice of engine version
Hi, I’m having problems in 3_GA_UMP, there doesn’t seem to be a tag for that lesson so whenever I ask the question it gets posted to nowhere (not showing under the video) so I’m posting here. The video is “Overhead Names” and I can’t get the names to show (I can when manually typing it in the editor/inspector). The problem is that userData returns null so I can’t access the name, it’s likely I botched some logic on a prior lesson regarding saving the name data.
I get this error code:
NullReferenceException: Object reference not set to an instance of an object
TankPlayer.OnNetworkSpawn () (at Assets/Scripts/Core/Player/TankPlayer.cs:25)
Unity.Netcode.NetworkBehaviour.VisibleOnNetworkSpawn () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkBehaviour.cs:497)
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.NetworkBehaviour:VisibleOnNetworkSpawn() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkBehaviour.cs:501)
Unity.Netcode.NetworkObject:InvokeBehaviourNetworkSpawn() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkObject.cs:1066)
Unity.Netcode.NetworkSpawnManager:SpawnNetworkObjectLocallyCommon(NetworkObject, UInt64, Boolean, Boolean, UInt64, Boolean) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Spawning/NetworkSpawnManager.cs:636)
Unity.Netcode.NetworkSpawnManager:SpawnNetworkObjectLocally(NetworkObject, UInt64, Boolean, Boolean, UInt64, Boolean) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Spawning/NetworkSpawnManager.cs:539)
Unity.Netcode.NetworkConnectionManager:HandleConnectionApproval(UInt64, ConnectionApprovalResponse) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Connection/NetworkConnectionManager.cs:610)
Unity.Netcode.NetworkManager:HostServerInitialize() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkManager.cs:895)
Unity.Netcode.NetworkManager:StartHost() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkManager.cs:851)
<StartHostAsync>d__9:MoveNext() (at Assets/Scripts/Networking/Host/HostGameManager.cs:100)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(Lobby)
Unity.Services.Lobbies.Internal.<CreateLobbyAsync>d__4:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/SDK/WrappedLobbyService.cs:67)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(Response`1)
Unity.Services.Lobbies.Internal.<TryCatchRequest>d__20`2:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/SDK/WrappedLobbyService.cs:390)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(Response`1)
Unity.Services.Lobbies.Apis.Lobby.<CreateLobbyAsync>d__6:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Apis/LobbyApi.cs:236)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(HttpClientResponse)
Unity.Services.Lobbies.Http.<MakeRequestAsync>d__3:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:47)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(HttpClientResponse)
Unity.Services.Lobbies.Http.<CreateWebRequestAsync>d__7:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:138)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(HttpClientResponse)
Unity.Services.Lobbies.Http.<<CreateWebRequestAsync>b__0>d:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:135)
System.Threading.Tasks.TaskCompletionSource`1:SetResult(HttpClientResponse)
Unity.Services.Lobbies.Http.<>c__DisplayClass0_0:<GetAwaiter>b__0(AsyncOperation) (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/UnityWebRequestHelpers.cs:34)
UnityEngine.AsyncOperation:InvokeCompletionEvent()
Hello,
I just wanted to thank you for following up with this temporary fix and for confirming that this won’t be an issue later on in the course. I was experiencing the same issue and felt rather hopeless prior to stumbling upon this response. It is greatly appreciated!
I think you should be able to downgrade to 2022.2 with minimal problems in editor (I did that), but you probably shouldn’t worry about it, I did it to avoid any further unexpected bugs (eg. when I ran into the name missing, but that seems to be another problem probably due to my oversight), and it seems that the bug we talk here only happens when you anchor to top left, possibly it also only happens on the FIRST loaded scene, because even on 2022.3 I no longer had any issues besides in this lesson.
It looks like the issue relates to line 25 of the TankPlayer.cs script and so its not got the reference there either as its incorrect,missing or its a race condition and hasnt got it before its trying to call on it.
If you can post the TankPlayer.cs script we can take a look and try and track what might be causing that issue
The script:
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
using Cinemachine;
using Unity.Collections;
public class TankPlayer : NetworkBehaviour
{
[Header("References")]
[SerializeField] private CinemachineVirtualCamera virtualCamera;
[Header("Settings")]
[SerializeField] private int ownerPriority = 15;
public NetworkVariable<FixedString32Bytes> PlayerName = new NetworkVariable<FixedString32Bytes>();
public override void OnNetworkSpawn()
{
if(IsServer)
{
Debug.Log("ACCESSING Network server user data");
UserData userData =
HostSingleton.Instance.GameManager.NetworkServer.GetUserDataByClientId(OwnerClientId);
if (userData == null)
{
Debug.Log("NULL problem");
}
Debug.Log("Ayayay " + userData);
Debug.Log("Ayayay2 " + userData.userName);
PlayerName.Value = userData.userName;
}
if(IsOwner)
{
virtualCamera.Priority = ownerPriority;
}
}
}
I added some debug log codes so now the line 30 is trouble, here is the new error log:
NullReferenceException: Object reference not set to an instance of an object
TankPlayer.OnNetworkSpawn () (at Assets/Scripts/Core/Player/TankPlayer.cs:30)
Unity.Netcode.NetworkBehaviour.VisibleOnNetworkSpawn () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkBehaviour.cs:497)
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.NetworkBehaviour:VisibleOnNetworkSpawn() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkBehaviour.cs:501)
Unity.Netcode.NetworkObject:InvokeBehaviourNetworkSpawn() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkObject.cs:1066)
Unity.Netcode.NetworkSpawnManager:SpawnNetworkObjectLocallyCommon(NetworkObject, UInt64, Boolean, Boolean, UInt64, Boolean) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Spawning/NetworkSpawnManager.cs:636)
Unity.Netcode.NetworkSpawnManager:SpawnNetworkObjectLocally(NetworkObject, UInt64, Boolean, Boolean, UInt64, Boolean) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Spawning/NetworkSpawnManager.cs:539)
Unity.Netcode.NetworkConnectionManager:HandleConnectionApproval(UInt64, ConnectionApprovalResponse) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Connection/NetworkConnectionManager.cs:610)
Unity.Netcode.NetworkManager:HostServerInitialize() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkManager.cs:895)
Unity.Netcode.NetworkManager:StartHost() (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkManager.cs:851)
<StartHostAsync>d__9:MoveNext() (at Assets/Scripts/Networking/Host/HostGameManager.cs:102)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(Lobby)
Unity.Services.Lobbies.Internal.<CreateLobbyAsync>d__4:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/SDK/WrappedLobbyService.cs:67)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(Response`1)
Unity.Services.Lobbies.Internal.<TryCatchRequest>d__20`2:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/SDK/WrappedLobbyService.cs:390)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(Response`1)
Unity.Services.Lobbies.Apis.Lobby.<CreateLobbyAsync>d__6:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Apis/LobbyApi.cs:236)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(HttpClientResponse)
Unity.Services.Lobbies.Http.<MakeRequestAsync>d__3:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:47)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(HttpClientResponse)
Unity.Services.Lobbies.Http.<CreateWebRequestAsync>d__7:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:138)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(HttpClientResponse)
Unity.Services.Lobbies.Http.<<CreateWebRequestAsync>b__0>d:MoveNext() (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:135)
System.Threading.Tasks.TaskCompletionSource`1:SetResult(HttpClientResponse)
Unity.Services.Lobbies.Http.<>c__DisplayClass0_0:<GetAwaiter>b__0(AsyncOperation) (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/UnityWebRequestHelpers.cs:34)
UnityEngine.AsyncOperation:InvokeCompletionEvent()
This would be whats causing the null reference i think as its not getting the OwnerClientId which is weird as i would have thought the null check would have provided the message in the console.
I would check the resources and check the code from the previous lecture as i think you are right that where its getting the OwnerClientId is incorrect.
You can compare your code using the below site as often i find it easier to find a bug of my own creation.
Let me know if you find anything and if not i’ll grab your project and have a look at it
EDIT: SOLVED, I had to enable connection approval, as described bellow
TL;DR OwnerClientId has no value (parameter of method) and we never give it a value. How is it used in the course version? Why does it work there?
I apologize for the confusion! The debug log I added does indeed trigger, the last message I get on debug console is “Ayayay” from the code
if(IsServer)
{
Debug.Log("ACCESSING Network server user data");
UserData userData =
HostSingleton.Instance.GameManager.NetworkServer.GetUserDataByClientId(OwnerClientId);
if (userData == null)
{
Debug.Log("NULL problem");
}
Debug.Log("Ayayay " + userData);
Debug.Log("Ayayay2 " + userData.userName);
PlayerName.Value = userData.userName;
}
The error happens once it calls the userData, and thus “Ayayay2” never prints out.
I tracked the bug further down to NetworkServer.cs to the following method:
public UserData GetUserDataByClientId(ulong clientId)
{
Debug.Log("DATA TRY GET CLIENT AUTH ID VALUE");
Debug.Log(clientId);
if(clientIdToAuth.TryGetValue(clientId, out string authId))
{
Debug.Log("DATA TRY GET DATA VALUE");
Debug.Log(authId);
if(authIdToUserData.TryGetValue(authId, out UserData data))
{
return data;
Debug.Log("DATA GET USER DATA");
Debug.Log("Heyoo" + data);
}
return null;
}
return null;
}
Here
Debug.Log("DATA TRY GET DATA VALUE");
Debug.Log(authId);
print out “DATA TRY GET DATA VALUE” followed by a 0, so no if statement further down the line does anything and I just get a return null.
Since it’s at the very start of the GetUserDataByClientId method it recieves no valid parameter to begin with, so I added Debug.Log(OwnerClientId) at the start of the method in PlayerTank and indeed, it returns nothing.
OwnerClientId is the culprit, it has no value!
We never give a value to OwnerClientId, and I checked even in the final version of the commit it’s used twice but we never give a value to it. I have to check out a few things that might be the solution, maybe this new info is enough for you to know the solution? Let me know if you do
EDIT: SOLVED! Just had to tick Connection Approval in the Network Manager
Another potential problem!
I posted it a while ago but some videos have their tag system bugged so it dissapears.
I get [Netcode] A ConnectionApproval callback is defined but ConnectionApproval is disabled. In order to use ConnectionApproval it has to be explicitly enabled ever since
Any idea where I need to enable ConnectionApproval? I’ll rewatch the video in case I missed something
[Netcode] A ConnectionApproval callback is defined but ConnectionApproval is disabled. In order to use ConnectionApproval it has to be explicitly enabled
UnityEngine.Debug:LogWarning (object)
Unity.Netcode.NetworkLog:LogWarning (string) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Logging/NetworkLog.cs:28)
Unity.Netcode.NetworkManager:CanStart (Unity.Netcode.NetworkManager/StartType) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkManager.cs:723)
Unity.Netcode.NetworkManager:StartHost () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkManager.cs:831)
HostGameManager/<StartHostAsync>d__9:MoveNext () (at Assets/Scripts/Networking/Host/HostGameManager.cs:102)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Models.Lobby>:SetResult (Unity.Services.Lobbies.Models.Lobby)
Unity.Services.Lobbies.Internal.WrappedLobbyService/<CreateLobbyAsync>d__4:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/SDK/WrappedLobbyService.cs:67)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Response`1<Unity.Services.Lobbies.Models.Lobby>>:SetResult (Unity.Services.Lobbies.Response`1<Unity.Services.Lobbies.Models.Lobby>)
Unity.Services.Lobbies.Internal.WrappedLobbyService/<TryCatchRequest>d__20`2<Unity.Services.Lobbies.Lobby.CreateLobbyRequest, Unity.Services.Lobbies.Models.Lobby>:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/SDK/WrappedLobbyService.cs:390)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Response`1<Unity.Services.Lobbies.Models.Lobby>>:SetResult (Unity.Services.Lobbies.Response`1<Unity.Services.Lobbies.Models.Lobby>)
Unity.Services.Lobbies.Apis.Lobby.LobbyApiClient/<CreateLobbyAsync>d__6:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Apis/LobbyApi.cs:236)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.HttpClient/<MakeRequestAsync>d__3:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:47)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.HttpClient/<CreateWebRequestAsync>d__7:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:138)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.HttpClient/<>c__DisplayClass7_0/<<CreateWebRequestAsync>b__0>d:MoveNext () (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/HttpClient.cs:135)
System.Threading.Tasks.TaskCompletionSource`1<Unity.Services.Lobbies.Http.HttpClientResponse>:SetResult (Unity.Services.Lobbies.Http.HttpClientResponse)
Unity.Services.Lobbies.Http.UnityWebRequestHelpers/<>c__DisplayClass0_0:<GetAwaiter>b__0 (UnityEngine.AsyncOperation) (at ./Library/PackageCache/com.unity.services.lobby@1.0.3/Runtime/Http/UnityWebRequestHelpers.cs:34)
UnityEngine.AsyncOperation:InvokeCompletionEvent ()
A new bug (I got to random spawn lesson so I apologize if it gets fixed later) is that once a player disconnects he can no longer connect the same server since he’s still there, I’m pretty sure that wasn’t a problem before (I believe I entered and left the same server several time to one host with no issue) and that it was solved with the shutting down cleanly lesson, now I even get errors of the like “no host singleton found” once I shut down the game on the editor.
Any player can only enter a server once
Hi Zoki,
I believe that is by design for not being able to rejoin the same server as i’m pretty sure Nathan mentions it in a video as its complicated to get them to remember the server they were in.
The No Host Singleton bug we may fix in the clean up lectures as it just involves removing a debug.log we left in.
I am looking into the backfilling question though as my thoughts are that when backfilling it should fill up populated servers first and we arent doing that in our code.
It may be beyond the scope of the course but from playing battle bit remastered using UGS is certainly should be possible.
I will test to prove out that it does in fact not join the same server and if not i can approach Nathan to see if its beyond the scope of the course or something we need to look at (I am leaning towards it being a bit out of scope)
Hope this helps
Edit :- I have done multiple tests on my project so you may need to check yours is set up correctly.
It does not save the progress of coin collection, current health etc as that is beyond the scope of our course but mine does consistently join the same server.
Now this could be because its only spun up one server so there is no guarantee that if you have lots of players and multiple servers that you will join the same server again (As far as i know) but that would be beyond the scope of the course of tracking the last server id that you connected to and not sure its even possible.
Thanks for the answer, now I remember that he mentioned something that the score will be kept, I’ll go snoop around for solutions once I finish the course