Giter VIP home page Giter VIP logo

loadingbdtreesnotes's Introduction

LoadingBdTreesNotes

Some performance notes/tips when using Behavior Designer 1.6.3 Asynchronous Loading

I've finally got to the point in my game project where I need to start optimzing things. As I have been I noticed that when I was enabling 10-20 enemies at a time during the game(think Monster Closets) the game was freezing for a few frames. I checked the profiler and when my Behavior Trees were being enabled they were generating 20 mb of Garbage(GC) and causing a 460ms hit to the frame rate 0_0

I upgraded to Behavior Designer 1.6.3 as it has an Asynchronous loading of trees- I tried it out and got some errors. As of right now it seems Async Loading throws errors on some Movement Pack tasks- here is how to fix those errors. The errors are caused by some initializion code in those tasks not being thread safe. Anyway its a simple fix.

You have to change the following tasks- CanSeeObject, WithinDistance, Search

On CanSeeObject make line 24 look like this-

public LayerMask ignoreLayerMask;

line 49 like this-

private int ignoreRaycastLayer;

and add this on line 50 or 51-

public override void OnStart()
{
           base.OnStart();
           ignoreRaycastLayer = LayerMask.NameToLayer("Ignore Raycast");
}

On WithinDistance make line 26 look like this-

public LayerMask ignoreLayerMask;

Delete line 119

On Search make line 28 look like this-

public LayerMask ignoreLayerMask;

That should do it!

Here's a chart showing the performance improvements in my game loading a group of enemies during gameplay-

alt text

As you can see just using Async loading gives a huge performance boost- here's how to get more using Mec (More Effective Coroutines) which is a free on the asset store.

What I did was very simple- I add all my Enemies with Btrees to a list- then to activate them I loop through the list and wait a single frame between activations like so- here's a simple example of what I did-

 IEnumerator<float> _DelayedActivation()
    {
        for (int index = 0; index < EnemySpawns.Count; index++)
        {
            var i = EnemySpawns[index];

            ActivationProcess(i);
            yield return Timing.WaitForOneFrame;           
         }

        yield break;
      }

In Summary- using Async Loading in Behavior Designer gives you a huge boost + waiting a frame between loading your enemies/agents using a tool like MEC that doesn't generate garbage helps too. I've read about pooling external behavior trees for performance gains but haven't tried that yet.

loadingbdtreesnotes's People

Contributors

mdotstrange avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.