BP node with dropdown input

Hi! I wonder if is possible to create a BlueprintCallable function
with dropdown inputs for classes like GameMode, GameInstance and PlayerController
like this:

image

Why should I want this?
Because I use a BP custom function where I call, cast and store those 3 classes like this:

image

the problem is that I have to hardcode the cast type for each class and i want to add dropdown menus to the node so can be reused in any project witout edit the function.
I ask here because I plan to redo in C++

here is s mockup of what I want to achieve:

image

thanks!

Let me start by saying this may not be a good function to try and write in a reusable way. Generally, your going to be better off just casting them manually so that you can do the appropriate error handling if they fail (game mode and player controller type especially since they can easily be different across different parts of the same game). Also you usually don’t need all three as a group like that so you’re probably getting and casting two of those unnecessarily a lot of the time.

It’s also worth saying that you may be trying to generalize too soon. Do you have another project that needs it. You may want to finish your first one so you better understand how you end up using that node before you generalize. This is similar to the adage about “premature optimizations”.

That being said, it is possible to achieve. A couple of things that seem like they might work, but won’t. Macros: first of all macros seem to require that all the outputs are the same type which won’t work here. I’ve also had zero luck getting an output pin to change type based on any other pin but one involving a wildcard. Both of which won’t work for you. UFUNCTION: Functions have an option with the DeterminesOutputType markup to dynamically change the type of the output pin, but I can’t imagine it will work with multiple output pins.

This leaves Custom K2 nodes. There’s not a whole lot of documentation about how to make them but I’ve done a bit of a write up about them here. But the reason I started off with the first two paragraphs is that they can be sort of complicated and fiddly in ways that you really want to make sure you need it and understand your problem before you use it. And dynamic pin types even more so.

Ultimately you have two options: 1) class selection input pins or 2) the properties panel. Class selection input pins would be the same as if you had a Class or Soft Class input to your function. You get the drop down, but it could also be connected up to a variable (which isn’t much help because your output pin has to be a compile time determined type). The other option is to move those class selections to the properties panel so that while the node is selected you modify them there and not on the actual node. Both of these features are covered in more detail my writeup.

There might be a third option which involves not only a Custom K2 node, but a custom slate widget to render it. I don’t know if there’s a way to get exactly what you want. So far I only know that you can add more widgets below all the input/output pins. I’m not sure if there’s any way to intersperse them like your picture.

3 Likes

Hey!!! Thank you very much for such a very good developed answer!

in BP most of the time I do getplayercontroller–>casto to myplayercontroller—>promote to variable and then I use the variable instead of casting all the time. I do the same with gamemode and with gameinstance. The BP shown in the original post uses 3 differenf functions inside like this:

I feed the node with my gamemode variable were I want to store it, then inside the function it gets current gamemode, casto to MY CUSTOM gamemode and set my variable by ref. so this two things are the same:

yes I know…i just save a node lol. but as sometimes blueprints turns in spaghettis sometimes and I have some OCT I like to save nodes. Also If you save 1 node each time you apply in a game and you do it hundred of times is quite a big time you save just by adding another node in the row. I use other custom functions like this:

image

another reason is I am relatively new into C++ and I am avid for learning and this seems a nice challenge to achieve :slight_smile:
So basically I would like to know if there is some way to use as input a list of available gamemodes in the assets like you use dropdown menus for choosing a material from assets like this:

image

Thanks again for taking your time man!
Best

Dany

Yeah, I get what you’re doing. I’m just suggesting it might be a bad idea, but you gotta do you and explore and mess around if you’re new at this. That float version is particularly bad. A better option for this sort of cleanup would be using the “Collapsed Nodes” option that lets you organize without creating functions that aren’t actually reuseable.

Did you only read the part where I said it was bad without reading the rest? I told you how you’d be able to do it. There isn’t an easy way to do it because none of the other ways to make a node will let you manipulate the types of the input and output pins in the way that you’d need.

In fact, with a custom node you’d be able to avoid the drop-down entirely and it would be able to get the game mode and cast it to whatever type your input variable was. But that’s even more advanced.

1 Like

OK I also noted that even I achieve the dropdown thing (selecting a specific gamemode to cast)
I dont have an option to cast to ‘a specific gamemode’ and then assign to ‘a specific gamemode’ type of variable :slight_smile:
Too complicated. I surrender!