- Home /
can ContextMenu pass arguments into a method?
I'm currently doing this sort of thing - a lot - to test run methods from the inspector as I go
[ContextMenu("Do Something")]
void DoSomething()
{
Debug.Log("Did something");
}
But when my methods have arguments I hate to add/modify stuff just for testing - without knowing if there might be something like this:
[ContextMenu("Do Something").With( this )]
void DoSomething( this )
{
Debug.Log("Did something with this");
}
Thanks (nooby question)
Answer by Casiell · Sep 27, 2021 at 07:53 AM
https://docs.unity3d.com/ScriptReference/ContextMenu-ctor.html
I don't think so, there is no constructor for that, and nothing in the documentation.
Usually I would just write an overload to the method with no parameters that calls the overload you actually want to with some default parameters. Or maybe add those parameters on class level if I need quick prototyping with multiple different values.
If the new method is only for debug, wrap it in "#if Unity_Editor" preprocessor directive block.
I know it's not ideal, but it is what it is. I'm thinking maybe Odin will have a solution for that, they usually do
Damn, well I guess it's not that bad.
I never even thought about setting up another class to hold a variety of values/references, that could be a great little tool for debugging and testing actually.
Thanks for the reply.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Collider just for Tag (2D) (C#) 1 Answer