Access properties & fields of Dynamic Vars

Forums 💬 NodeCanvas 🗨️ General Discussion Access properties & fields of Dynamic Vars

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #14321
    jonc
    Participant

      Hi,

      In my behaviour tree I make the AI search for a type called ‘lamp’ via a custom GetClosestOfType<T> action, which stores the closest lamp as a Dynamic Variable, so far so good. Now, this lamp class has an ‘active’ bool property which controls the sprite replacment, light shading, etc..

      What I would need to do, is to access this property to check inside NC if the lamp is currently active or not, so that I can then collect a list of lamps that are active and one list with those that are not, but I have no clue how this is done. Accessing the properties and fields of Dynamic Variables would be a huge help. Is this possible? Or can I filter it directly inside GetClosestOfType<T> via Linq and expose it visually in the node?

      This is the class:

      #14328
      Gavalakis
      Keymaster

        Hey,

        If you want to manually access a variable value (dynamic or not), from within your custom task, you can do so by calling:
        blackboard.GetValue<T>(string name). So, for example blackboard.GetValue<Lamp>("myLamp")

        You can also use a public BBParameter<Lamp> lamp variable in your task which will expose a parameter of type Lamp in the inspector, which you can set to also be dynamic and type in the name of the variable that should get it’s value from. In this case, if a dynamic variable has not yet been generated by your GetClosestOfType action, the ‘lamp.value’ will simply return null for this example.

        Please let me know if this is what you ment, or maybe I completely misunderstood the question which I think is quite possible in this case 🙂

        Thanks.

        #14327
        jonc
        Participant

          Hello,

          sorry for being not clear. So, I find the closest type “Lamp” in NC with the GetClosestOfType action and cache it as a dynamic var (Of which implementation was a brilliant idea by the way!) Now I need to access a public bool property inside that class “Lamp”, but since “Lamp” is a dynamic variable, I don’t know how to best accomplish this.

          I know, I could work around this by scripting certain methods and special actions, but I just wanted to make sure, that I don’t overlook an easier approach.

          A pseudo version of the class would be:

          Thanks!

          #14326
          Gavalakis
          Keymaster

            Hey,
            Don’t worry about and thanks! 🙂

            So, if you are refering to accesing the property with the ‘GetProperty’ script control task, that would be impossible right now, because the ‘GetProperty’ action can’t work with dynamic variables since the option for “(DynamicVar)” does not exist in the variable dropdown selection for when selecting a variable for the target agent (replacing “Self”).
            If the above is what you need, I can certainly allow dynamic vars here. I just haven’t done this yet to avoid possible confusions and errors by wrong typed variables.

            The only alternative solution right now would be to create a custom task to access that property like for example:

            In a future version, I plan on allowing a property of a variable to be selected directly within the dropdown parameter selection. So that if for example you have a BBParameter, you would be able to link it to a bool property of any variable on the blackboard directly 🙂
            This feature is comming rather soon.

            Thanks!

            #14325
            jonc
            Participant

              Hi,

              if you could make dynamic variables available for the GetProperty action, that would be very helpful. Until then I’ll work around with custom classes like yours above. 🙂

              Thanks alot, Gavalakis!

              #14324
              Gavalakis
              Keymaster

                You are welcome 🙂
                I will allow dynamic variables for overriding agent parameter (thus possible to use GetProperty with them) in the version after the one already submited and pending review in the asset store.

                Thanks!

                #14323
                jonc
                Participant

                  Oh, know I understand, what you mean by replacing it with ‘Self’ a.k.a. agent parameter. Hell, that’s a wonderful idea!

                  #14322
                  Gavalakis
                  Keymaster

                    Hehe 🙂
                    Glad to know you like it 🙂

                    Thanks!

                  Viewing 8 posts - 1 through 8 (of 8 total)
                  • You must be logged in to reply to this topic.