Is there a way to customize the string a value input shows?
In the example below “Message” should actually be an integer which is used as the index to a list. In order for the value to be better readable in the canvas, I’d love the text to be the content of the message, not the index of the message.
For now I made this work by wrapping the index in a serializable struct that also holds a text and overrides ToString to show that text. But this of course now means I wouldn’t be able to just plug in any integer into this port, I’d need to convert it to such a struct first.
I also want to show a dropdown in the inspector for that field, instead of an integer field. I achieved this by overriding OnNodeInspectorGUI.
However I had to create a base class since I need similar functionality in other places. I’d love to be able to use an attribute drawer, but in standard simplex nodes and even Full nodes, there’s nothing to put the attribute on. You just have “AddValueInput” and that’s it. On simplex nodes you have nothing at all.
Is there any easier way to achieve these usecases without a custom struct for the port text and without overriding OnNodeInspectorGUI for the dropdown?
Hello,
There is no way to customize the text shown left of the value ports since the text shown there is based on the type of the port and the value that is serialized within that node for that port. You could however create an integer constant variable node and link that to the “Message” if integer is an acceptable type for the port. Would that work for you?
As for showing a dropdown of integers, you could use the “PopupFieldAttribute” on the field to make a popup of predefined integers able to set the field to. Let me know if that works for you.
I’m not sure what you mean by Attribute on the field. Ports are created by just calling “AddValuePort”.. there’s no field to put the attribute on?
Also the entire point is NOT to show integers but the text the integers refer to. A mission designers cannot identify a message that is to be sent by its integer, even though that’s how it’s serialized. The integer is an index to a list of messages and I’d like to display that message text on the node, so a mission designer knows what message the node is referring to.
As I said I worked around this by createing a struct that constains a string and the integer and make the port of that type. But that makes the port no longer a pure integer which leaves it less flexible. if I ever want to actually plug in a dynamic index, I’d have to add a converter node that turns it into my serialized type. I was hoping there’d be some other way to achieve this but apparently not.
Maybe it’s an idea for the future to offer a function that turns a serialized value into a string that is displayed on the port. You don’t always want to see just value.ToString there. Sometimes a built in type like boolean or integer has more semantic behind it, and it would be nice to be able to display that.