Announcement

Collapse
No announcement yet.

Any way to make parameters a generic type in Blueprint?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Any way to make parameters a generic type in Blueprint?

    To clarify what I mean: I want something like the "select" node, or Java Generics, or C++ Templates. Specifically, I want to create a UMG widget that can store a number of variables of a given type - maybe int, float, string, an enum - and select between them. This means (probably, I mean it's how I'd do it in Java or C++) it has to accept an array of a generic type, and an instance of it stores and returns based on the type it was given.

    Can I do this in Blueprint? (Meaning, I'm not defining new nodes in C++, I'm just using BP). In practice I only need widgets for an int and a few enum types but that's still a lot of duplicating code I'd rather avoid.

    #2
    You can add parameters to your functions or custom events. I havent tried it, but you should be able to convert a parameter to an array of the same type. From there, its up to you how you want to handle the input parameter inside the function.

    One common example I use is having an Int as a parameter for my function and then using Switch on Int inside the function to then decide what to do (assuming the Int is an ID of some sort).
    [WIP] Procedural City Generator | RPG AI
    [MARKETPLACE] Animal Behavior Kit | Space Shooter Template | Procedural Foliage Tool | Procedural Park
    [FREE] Modular Road Tool | Action Platformer Template | Radar BP | Free Birds | Procedural Buildings
    Join our Discord

    Comment


      #3
      Yes but (in your example) it would have to be an int array, so you couldn't use the same widget to handle a float array, string array, enum type etc. That's what I wanted to define parametrically at runtime: the type of the array.

      I ended up just using strings for everything and writing some kludgy functions to convert some of them back to different enum types. Pretty sure actual generics are impossible to set up just using Blueprint (and maybe even using C++? idk)

      Comment


        #4
        I see, you want to be able to pass a generic parameter (without a specified type). Not sure it can be done in BP, but I've only been using UE4 for a few months so there might be a way. I would post in the C++ forums and the Answer Hub (a lot of UE4 devs frequent the Hub) and see if someone more experienced can help

        Good luck!
        [WIP] Procedural City Generator | RPG AI
        [MARKETPLACE] Animal Behavior Kit | Space Shooter Template | Procedural Foliage Tool | Procedural Park
        [FREE] Modular Road Tool | Action Platformer Template | Radar BP | Free Birds | Procedural Buildings
        Join our Discord

        Comment


          #5
          Yeah, I read some posts that hinted this is hard to do even if you're defining a BP node in C++... My string solution "works" so I doubt I'll bother with it anymore. Thanks tho!

          Also, I used to post on answerhub but never got any help there. These forums are way more responsive and helpful. There aren't nearly as many questions with zero replies here as on the answerhub.

          Comment


            #6
            BP doesn't allow this in functions. But Macros have the ability to have a Wildcard Input. Which is automatically converted to the type you are plugging in.
            However, this is strictly limited. You can't access members from it within the macro.

            Comment

            Working...
            X