• Display UnityEvent<Vector3> in Inspector?
    6 replies, posted
In short, I want my artists and designers to have an easier time setting up UnityEvents, but I want them to be able to pass different properties. [System.Serializable] public class Vector3Event : UnityEvent<Vector3> {}; public class InteractableVector3 : Interactable {     public Vector3 Vec3;     public Vector3Event vec3Event;     public override void Interact()     {         base.Interact();         vec3Event.Invoke(Vec3);     } } This is my hacky workaround. You can see the problem with this pretty quickly though. https://files.facepunch.com/forum/upload/107155/88edc5e5-80c4-4a4d-b7b4-5a6fc17ae3f8/dank.png The user can only ever pass in the same Vector3 for every listener in the event. I can't draw a custom inspector for the InteractableVector3 class because it's not an object. My goal is pretty much to create a user friendly gui that my team can use to set up events that can pass a Vector3. Anyone have any ideas?
If you just use a UnityEvent with no arguments, and choose that function - I think you're able to pass in arguments manually?
UnityEvents with no arguments let you pass is int, bool, float, ect. Not a non-standard type like Vector 3.
Oh. You could pass it in as a string and parse it, but that might be a bit shitty for you I guess.
What about Scriptable Objects? UnityEvents let you also pass GameObjects and Scriptable Objects. You could pass a Scriptable Objects with a Vector3 in it. They're easy to create: your team can easily create one by clicking on Assets -> Create -> "Name of SO".
This would be awesome if I didn't have to override existing Unity functions to pass an SO. If I wanted to call Rigidbody.AddForce for example, wouldn't I need some sort of helper script that contains a method that takes the SO, and then calls AddForce?
UnityEvent is not derived from UnityEngine.Object, so CustomInspector won't work. Custom inspector for [Serializable] classes uses PropertyDrawer. Unity just released their C# side of Unity as free to read, so if you really need to expose it and willing to go for extra mile for it, this is the PropertyDrawer class for UnityEvent, and UnityEventBase for reference. Probably what you need to do is make your own, limited version of PersistentCallGroup and PersistentCall that only takes a Vector3, figure out the way to list relevant methods (see BuildPopupList method in UnityEventDrawer.cs), then draw the property the same way (take a look at m_ReorderableList callbacks in UnityEventDrawer.cs) except with the added Vector3 input component.
Sorry, you need to Log In to post a reply to this thread.