Announcement

Collapse
No announcement yet.

Is there a way to have a “Variable Variable”

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

    Is there a way to have a “Variable Variable”

    So I did some googleing and some thinking, but I can’t find anyway to do what I want. I’m going to try and explain it and see if anyone here has a solution, but it sounds awfully convoluted when I try, so bare with me.

    I’m trying to create a skill test system, where you walk up to an object, use that object, then it checks to see if the user has that skill. If it does, then it does a bunch of fancy math to see if you pass the test or not. I have this part working smashingly and was quite happy with little network I built to handle it, but the one issue I have here is in efficient implementation.

    What I want to do is to turn this object into the parent class for any useable object that requires a skill check to activate, but I cannot do that if I have to go back and manually replace two blueprint nodes for each object.

    Here is the setup:


    What I want here is a variable that sets another variable, like an enum that would give me a dropdown on any child classes and allow me to just select “Skill 1” or “Skill 2”.

    I am admittedly new'ish at doing more complex blueprint work, so maybe there is a way to do this, but so far all I can think of is something like

    This:


    Or this:


    Both ways seem like objectively terrible method of going about this to me. They’re messy and the more skills you add the vastly worse the network there will become. I have no idea what the actual resource cost of having a hundred or so nodes in a nightmarishly long switch would be, but it irks me severely to think that’s the only way to go about this.

    So I ask, is there no more streamlined/sane way to go about doing something like this in blueprint?
    Attached Files

    #2
    What you are looking for is the "Wildcard" type

    Comment


      #3
      There are several ways to do this.

      One quick possibility.
      You could go the route you are with the parent class. You could also just make an Interace and have whatever interactable object call the Interface method. You don't need to cast, it will just fail silently. Whatever the callee is, can cast the caller and then respond according to type.

      Comment


        #4
        Originally posted by KVogler View Post
        What you are looking for is the "Wildcard" type
        The only thing with the word wildcard in it that I can find documentation on is the "Matches Wildcard" node for strings, and I haven't the faintest idea how i'd use that to select a integer variable on a different actor without a ridiculously dense network of notes. Am I looking at the wrong thing?

        Originally posted by mikepurvis View Post
        There are several ways to do this.

        One quick possibility.
        You could go the route you are with the parent class. You could also just make an Interace and have whatever interactable object call the Interface method. You don't need to cast, it will just fail silently. Whatever the callee is, can cast the caller and then respond according to type.
        I'm not clear on how I would choose the targeted variables in this method? I can convert the cast to a BP-Interface easily enough but how do I make it so the object can "ask" the player for the value of a variable based on yet another variable? Wouldn't I still have to construct a bunch of switches to direct it down some predefined path? I cannot see anything like a "Get Variable by Name" node that takes a enum output or anything similar, even though that'd be massively useful.

        Sorry again if this is unclear or if it's just something rudimentary that I'm unaware of, I just feel like anytime I have to copy node networks between objects more then once, just to change one or two nodes, that there must be a better way of doing things.

        Comment


          #5
          The only thing with the word wildcard in it that I can find documentation on is the "Matches Wildcard" node for strings
          This is what I mean:
          When you select a variable and make it wildcard type. You can then perform generic actions on the type set by the connected variable type.

          This example takes an array of whatever type and removes all elements, except for the first one.

          Click image for larger version

Name:	wildcard.JPG
Views:	1
Size:	94.2 KB
ID:	1101397

          And in use....

          Click image for larger version

Name:	wildcarduse.JPG
Views:	1
Size:	54.4 KB
ID:	1101398

          Hope that explains it a bit

          Cheers,
          Klaus

          Comment


            #6
            Originally posted by Panicintrinsica View Post
            I can convert the cast to a BP-Interface easily enough but how do I make it so the object can "ask" the player for the value of a variable based on yet another variable? Wouldn't I still have to construct a bunch of switches to direct it down some predefined path? I cannot see anything like a "Get Variable by Name" node that takes a enum output or anything similar, even though that'd be massively useful.
            The Blueprint Interfaces unfortunately carry assumptions on how they work because of the name, but it's not like a C++ or C# Interface. You don't need to cast to it. You just call the Interface Function, it either works or fails silently. But ya, it would be a switch.

            For, get variable by name type operations. That stuff is called reflection, it's common in some Java programs. It has a real performance cost. Java doesn't have function pointers ( delegates ) which is why it's done there.

            There are tasks, you could make a bunch of tasks, then just call the one you want. The Strategy Game example uses them extensively, or at least it used to, I haven't looked at it in a couple years.

            Comment


              #7
              Fair enough.

              The cleanest way I’ve figured to solve the issues so far is that when the player uses the object, that object triggers an interface to make and then fetch two different arrays from the player that contain the values of all that player’s skills, then have the object select the correct skill by index number, and just have that index selected as a public variable.

              It works, and it’s accomplished my goal of letting me set the requested skill on any child objects without having to reproduce the entire network on a per-object basis. It’s not as “user friendly” as displaying the skills by name, but just keeping track of the index number for each skill is an acceptable compromise.

              Thank you two for the help/suggestions.

              Comment


                #8
                It’s not as “user friendly” as displaying the skills by name, but just keeping track of the index number for each skill is an acceptable compromise.
                You could use an Enum-Integer mapping here....

                Comment


                  #9
                  I don't know much about it, but there is a SkillSystem and GameTags in the engine. I believe they use it in Fortnight and it's the backbone of a MOBA style skill system. You may want to check into that. There are some threads about it, with warnings that it's complicated and requires a programmer but that it's fully functional and can support a large system and even has optimizations for multiplayer.

                  Comment


                    #10
                    Originally posted by KVogler View Post
                    You could use an Enum-Integer mapping here....
                    *cough*

                    Yes. Yes I could...

                    I'm uh... going to go do the glaringly obvious thing now. Thanks :P

                    Comment

                    Working...
                    X