ui onclick handler parameter to variable gets reset
So i have a button that has a custom script attached to it, which send the button name to player and stores it in an variable inside the player script. The problem is, on the server side, server player the variable is stored and logged out perfectly later when debugging, but when connecting as client and debugging out the variable, its always empty. Like it resets the variable automatically on the client side and i have no clue, because i'm not reseting it anywhere on my code, so is it a bug or do i have to do something specific?
Here is the callback to adding the handler after slot instantiation:
newSlot.transform.Find("Text").GetComponent<Button>().onClick.AddListener(delegate { myplayer.GetComponent<Player>().HasClickedInvItem(slotItemName); });
Here's the handler function:
public void HasClickedInvItem(string itemName)
{
clickedItemName = itemName;
}
Here's when i try to print it out, but get always null returned, even though the hasClickedInvItem shows that there's correct input.
if (Input.GetKeyDown (KeyCode.Z)) {
print("keycode.z selectedItemname (" + clickedItemName+ "); ");
//output: keycode.z selectedItemName null
}
Answer by saadminhas101 · Dec 20, 2015 at 11:38 AM
I am facing the same issue.
If anyone has any solutions to this, that would be highly appreciated.
Your answer
Follow this Question
Related Questions
How to reset already initialized variables individually through the inspector 2 Answers
EventSystem button not calling OnClick on Build, works running in Editor 1 Answer
Why my image is not appearing while it is checked as active? 1 Answer
is it possible to have two on click events in one button 1 Answer