I am working on a fairly simple multiplayer game with mirror, and fizzysteamworks, in unity, I have variable lobby sizes, so no set amount of people must be in a game scene at once; therefore, I am instatiating a UI prefab containing a raw image (for the player's profile image) and a text element (for player score). Here is a basic look at my code to instatiate just one:
[SerializeField] private GameObject scoreCardElement;
[SerializeField] private Transform canvas;
bool scoreCardCreated;
private void Update(){
if (!scoreCardCreated) InstantiateUIScoreCard();
private void InstantiateUIScoreCard(){
scoreCardElement = Instantiate(scoreCardElement, canvas);
NetworkServer.Spawn(scoreCardElement);
scoreCardCreated = true;
}
The code seems to spawn the element in the center on the host (as I want). But nothing spawns on the client.
Having done my own research, most people write "ensure that your prefab is registered in the NetworkManager"; the issue is, I have done so already. I have tried many things to fix this code. These include: putting the contents of InstantiateUIScoreCard() into Update() , obviously this would spawn an element every frame, but it was simply for testing. Making an additional [ClientRPC] function to set the parent of the spawned scoreCardElement. All of these did not work.
In the past, I had gotten an error from Steamworks regarding buffer limits, so checked if this instantiation exceeded the limit, but seemingly not.
Finally, in order to test if NetworkServer was working I attempted to replace scoreCardElement with a registered sphere prefab, while also removing the addition of a parent transform in the instatiation line i.e.
ballObj = Instantiate(ballObj)
NetworkServer.Spawn(ballObj)
This change seemed to work and yet doing so with the UI prefab seems to fail.
I am stumped on what feels like so simple a task, perhaps there is a specific protocol for Mirror regarding the instantiation/creation of UI Elements.
Any help would be greatly appreciated, thanks in advance.