- Home /
Method reference dropping from OnClick()
Problem: A method referenced by one of my buttons randomly comes up as "Missing":
Details: The referenced method is not static, although that shouldn't be an issue in 5. Here's the referenced script:
using UnityEngine;
using System.Collections;
public class MenuManager : MonoBehaviour
{
// …
//Referenced method
public void ShowMenu(Menu menu)
{
if(menu.IsPopup == false)
{
//Closes the current menu
if(CurrentMenu != null)
{
CurrentMenu.IsOpen = false;
CurrentMenu.IsActive = false;
}
//Sets new menu (target of function) to CurrentMenu, and opens current menu
CurrentMenu = menu;
CurrentMenu.IsOpen = true;
CurrentMenu.IsActive = true;
}
else
{
if(CurrentMenu != null)
{
CurrentMenu.IsOpen = false;
CurrentMenu.IsActive = true;
}
CurrentMenu = menu;
CurrentMenu.IsOpen = true;
CurrentMenu.IsActive = true;
}
}
}
The object that OnClick is referencing has the component script on it, and the method in the component shows up in the OnClick drop-down menu in editor:
Attempted Solutions: I'll replace the missing reference by reselecting it from the drop-down menu. Then I save and close Unity, reopen it a few times or work on other scripts, and the method shows up as Missing again. I've tried recreating the button wholesale, renaming the script, moving the script to a difference object in the Hierarchy and referencing it there-- all to no avail.
Desperately seeking help. Thanks for looking.
Haven't seen this issue since Unity 3 (0.0d I think) By any chance it is a prefab?
Two you have two conflicting scripts? By title or by classname?
Yes I had this issue in Unity 3 Here is the related forum talk about it but it was when using prefabs. http://www.tasharen.com/forum/index.php?topic=5937.0
No conflicting scripts or class names that I can find. Still no idea what's causing this behavior.
I notice that whenever I "fix" it, and then open and re-save the script, the method shows up as $$anonymous$$issing again. I have a feeling that something in Unity or my source control (GitHub) is resaving or rewriting the script on startup and causing the error. I still don't know how to fix it.
Answer by kblood · Jul 31, 2017 at 08:31 AM
I am currently looking into this as well. What you got so far seems interesting.
Since this is from 2015, maybe you found a solution?
Your answer
Follow this Question
Related Questions
Reference For Button Which Calls OnClick 4 Answers
[Solved] Button OnClick properties are missing after loading the scene 4 Answers
Button Listener Takes Reference But I Want to Pass Value? 1 Answer
How to trigger a button click from script 3 Answers
Button OnClick() only being called once? 3 Answers