I have a setup like this very often
Is there a way to pass a Vector3 argument or a triplet of float to a call?
I have a setup like this very often
Is there a way to pass a Vector3 argument or a triplet of float to a call?
UnityEvents are very particular on what methods you get to draw. Apparently methods taking Vector3 doesn’t work. That’s strange, I was pretty sure it used to work.
There’s a pretty straight forward workaround where you make a script that has the correct arguments as fields, and a single method with no parameters that does the thing you want to do. So if you want to call AddForce on a RigidBody, you make this script:
public class AddForceWrapper : MonoBehaviour {
public Rigidbody rb;
public Vector3 force;
public void AddForce() {
rb.AddForce(force);
}
}
And assign AddForceWrapper’s AddForce to your UnityEvent.
If you want something a little less cumbersome, I’ve made an open-source replacement for UnityEvent that supports and arbitrary number of argument of most types. You can download it here. It’ll allow you to call methods that take a Vector3. A word of warning, though: it’s not really battle-tested. I tried to replace most of the UnityEvents used in our game with it, and it seemed to work just as well, but no guarantees. If you end up using it, and there’s bugs, please tell me!