Enum-like struct-value selection in Blueprint Node

Hi,

Recently I stumbled upon the KismetInputLibrary. There are functions like the Equal (Key) function, which is pretty straight forward. However, when I use this node in a Blueprint, I can select the function inputs from a dropdown, as if it were an enum. I looked a bit into InputCoreTypes, where FKey is defined as a normal struct, with all default values being defined in EKeys (another struct).

I want to implement similar Blueprint-Nodes where I can select struct values from a collection of pre-defined constants. In particular, I want a “FTeam”-struct, which contains information like team name and team color. Since there should only be a pre-defined number of teams with specific values, I would like to define these as constants and use them in the same way I can use FKey. However, I wasn’t able to find out what exactly needs to be done, so that a drop-down of constants appears on the blueprint node pins. Can anyone point me in the correct direction?

Here a screenshot of the node, which I would like to “copy” for my FTeam struct:

57243-equal+(key).png

Thanks in advance, Elewyth

PS: I can somewhat replicate the behaviour by providing blueprint library functions, which simply return the pre-defined constant, but that seems like unnecessary overhead in code, as well as in the blueprint :confused:

57244-equal+(team).png

Interesting question. Overloading an existing Blueprint operator node sounds really useful.

Is there a reason you can’t use one of the struct’s values in the comparison? The team name, for example, sounds like something that needs to be unique and could easily be used to compare team affiliation.

True, I can do that. But first of all, that only works if I already have 2 instances of the struct to work with, and secondly I need to use “Break Team” for both FTeam-Inputs so I can compare the name.

However, this doesn’t work, if I statically want to check e.g. if a player is in the Orange team. Also, when spawning an Actor, I would like to choose what team the Actor should be spawned for, which would be nice, if I could select the value from a drop-down like the FKeys.

Example of how I’ve done it so far:

57284-spawncharacter.png

FKey got custom blueprint pin programed

https://github.com/EpicGames/UnrealEngine/blob/e607ba4d978c08a26e8e8e629dec0884bb161770/Engine/Source/Editor/GraphEditor/Private/KismetPins/SGraphPinKey.h
https://github.com/EpicGames/UnrealEngine/blob/8a80b5541f69a79abf5855668f39e1d643717600/Engine/Source/Editor/GraphEditor/Private/KismetPins/SGraphPinKey.cpp

Making pin class won’t be enouth as Slate is outside of reflection system, so it needs to be manually registed and looking at it, you need to create custom FGraphPanelPinFactory which will assign data type to proper pin and then register it with this function when you load up your code module (you do that in main module class which is contained in cpp and h with same name as your module, in StartupModule()):

https://docs.unrealengine.com/latest/INT/API/Editor/UnrealEd/FEdGraphUtilities/RegisterVisualPinFactory/index.html

I find this examples if FGraphPanelPinFactory in other engine modules which you can base on

https://github.com/EpicGames/UnrealEngine/blob/311e18ff369078e192a83f27834b45bdb288168a/Engine/Source/Editor/GameplayTagsEditor/Private/GameplayTagsGraphPanelPinFactory.h
https://github.com/EpicGames/UnrealEngine/blob/e607ba4d978c08a26e8e8e629dec0884bb161770/Engine/Source/Editor/GameplayAbilitiesEditor/Private/GameplayAbilitiesGraphPanelPinFactory.h

Keep in mind you entering Slate territory, which means you need to add “Slate” and “SlateCore” to “PrivateDependiesModules” in build scipt of your module.

Also keep in mind you also extending editor at this point, and in order for code to compile without editor, you need to filter it out with #if WITH_EDITOR or by creating sperate module that builds only when you make editor build, by placeing it only in “YourProjectNameEditor.Target.cs” buil;d script and not in the other one without “editor” in name.

3rd importent note is that if you use something that requires manual registering, you need to keep higenine by unregistering your pin when your module is unloaded (ShutdownModule() in your module class) with this function:

https://docs.unrealengine.com/latest/INT/API/Editor/UnrealEd/FEdGraphUtilities/UnregisterVisualPinFactory/index.html

If you don’t do that you might see wierd things happening, like duplications of UI elements and such. Not to mention if editor unloads your module and use the data type you registed, it will crash editor.

Thanks a lot for your detailed answer. I think this is a little bit too much trouble for what I wanted to use it for right now. But it’s definitely helpful to know, where to look, if I ever decide to go that way. I was afraid, that it would be something complicated like that :frowning: