I need a function that will save the Vector3 data to a script variable that can be called from a UnityEvent but it doesn’t show up. I really need a solution
You may expect to provide a static vector3 value to your otherwise parameterless event? That’s not possible since UnityEvents only support very basic values types or UnityEngine.Object references as static parameters. The only values that are supported as static arguments are those supported by the ArgumentCache class of the UnityEvent system. Specifically: a single int, float, string, bool or UnityEngine.Object value. Those are the only values you can statically specify inside the inspector for a single staticly provided argument.
When the actual event type accepts dynamic arguments, it would support any kind of argument type and up to 4?! arguments. Though in that case you can not staticly choose values passed to the callback / method in the inspector. Instead the caller of the event has to pass the arguments along.
I dont understand the issue here. If the value you need to be passed through is static, just set teh variable inside the script somewhere, if not, then take advantage of the dynamic method / value.
It depends on your specific usecase. You can specify the argument as a separate variable next to the event and pass it along when you actually call the event. What’s your exact usecase here? What is that vector used for?
Unfortunately, i think we would need a little more context to assist in this situtation. For the most part, the ins and outs of the event have been covered. Whats missing is the exact useage and expected outcome.
You can always create small delegate components. That’s not that clean but would work just fine.
public class StaticVector3Delegate : MonoBehaviour
{
public UnityEvent<Vector3> myEvent;
public Vector3 argument;
public void Run()
{
myEvent(argument);
}
}
Not tested, just written from scratch. Though you should get the idea. You can attach this component either to the receiver or the sender, hook up your Vector3 methods in myEvent and have the actual event call the Run method. You can specify the value you want to pass along in the “argument” value of that component.
Then, how could a hard coded value be of any use? I really think you would want to use dynamics, but again, maybe im still missing a large piece of the pie.