Hi! I wonder if is possible to create a BlueprintCallable function
with dropdown inputs for classes like GameMode, GameInstance and PlayerController
like this:
Why should I want this?
Because I use a BP custom function where I call, cast and store those 3 classes like this:
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++
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.
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:
another reason is I am relatively new into C++ and I am avid for learning and this seems a nice challenge to achieve
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:
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.
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
Too complicated. I surrender!