Getting Blackboard values by hash instead of string for performance?

Forums 💬 NodeCanvas ⚙️ Support Getting Blackboard values by hash instead of string for performance?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15940
    dharma_42
    Participant

      I really like NodeCanvas’s Blackboard, however I’m concerned with the performance costs associated with getting properties.

      Unity’s animator system, like the Blackboard, has a lot of getters and setters that take strings as parameters. But there’s a big performance with using strings like this. That’s why there’s Animator.StringToHash().

      Looking at the Blackboard API, I don’t see any way to use hashes instead of strings. Is this possible? How can I use hashes instead of strings here?

      #15941
      Gavalakis
      Keymaster

        Hello,

        There is no support for getting a variable by a hash (int). If you are concerned about the performance of creating a string each time you want to access a variable (creation of a string is where the performance cost will be), then you can either:

        A) Create a constant string that has the name of the variable you want to access and use that constant instead of creating a new string each timer you want to access a Blackboard Variable.

        OR

        B) Get a reference of the Variable object (Blackboard.GetVariable) and store it in a field. Then directly work with that variable reference (GetValue, SetValue) instead of finding the Variable through Blackboard each time you want to access it. This is the better option if you want to access a variable very frequently.

        Please note that these optimizations already happen in the context of accessing variables in Task and Nodes via BBParameters. So these are only relevant if you want to access blackboard variables manually and very frequently. If you do not access variables manually and very frequently then I think that you should really worry about the above optimizations 🙂

        Let me know if that helps.
        Thank you!

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