#The UI I Assigned to the Player is Having Problems

4 messages · Page 1 of 1 (latest)

abstract relic
#

I'm making a zombie shooting game, players level up as they kill zombies, this level is kept in a common pool, so they all level up at the same time.
At the end of the game, I want to open a Buff UI panel to select as many buffs as the player has leveled up. Everything works fine on the Host side, but as soon as the Client clicks on the button in the window that opens, he falls out of the game.
I proceeded as follows, when the player starts the game, I create a Buff Panel through the BuffSelectionUI script and assign the necessary button references. The BuffSelectionUI script is inside the player prafab.
When the game is over, I call the EndGame function from the GameManager with [Server] and this calls the [Server] ShowBuffSelection function in the PlayersManager.
ShowBuffSelection in turn calls the StartBuffSelection function in the BuffSelectionUI script inside the players via [TargetRpc].
Here the panel is opened and buttons are assigned.
So far, everything is working normally on the Client side, the buttons are assigned, the text of the buttons, etc. are written properly, but as soon as I click on the button, it gives a Null Reference and the Client drops out of the game. When I look at it with debug, the assignment is made at the beginning, but it gives null while the function is running. I am also sharing my code. Where could I have done wrong?

https://pastie.io/scxdyn.cs

wicked trail
abstract relic
# wicked trail lines 189, 200, 223 all look suspicious

buffButtons[index].onClick.AddListener(() => CmdSelectBuff(buff.buffType, buff.amount));

What is the problem here, I was trying to assign a function to the button, is it troublesome to assign a function marked with Command directly to the button?

currentPlayer.CmdApplyBuff(type, amount);

Here I call the [Command] CmdApplyBuff function in the PlayerStats function, I referenced PlayerStats directly from the prefab. My goal was to make the stats change when the player presses the button.

if (!isLocalPlayer) return;

I don't fully understand the error here, if the script is directly in the Player, don't I need to check localPlayer?

wicked trail