Question about ExternalBehaviour

OhJeongSeok

New member
Hello.

I'm developing the zombie FPS game.

My zombie has Behaviour tree.
Each zombie trace a player and attack a player.
I have a problem.
My game spawn a zombie using pool system.
When zombie spawned, zombie object activated.

There is a lot of overhead in the Behaviour.Start() function when zombies are spawned.
Zombie_Profile.png

For this reason, the frame is dropped.
As I was looking for a solution, I saw how to allocate externalBehaviour using a pool.

As in my case, if each zombie is chasing and attacking the player, can I use the external behavior pool to get a performance advantage?

setting1.png
setting2.png

How to solve this problem?
Thank you for reading
 
Pooling will eliminate a lot of the garbage creation at the start because it no longer has to deserialize the tree. The tree still will need to be initialized though. There was a recent thread about this that has some more info:

 
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PancakeRestaurant;
using Ez.Pooly;
using UnityEngine;
using BehaviorDesigner.Runtime;


public class ZombieSpawner : MonoBehaviour {

    public GameObject SpawnZombiePrefab;

    public float StartTime = 5.0f;
    public float SpawnInterval = 1.0f;

    public int SpawnZombieCount = 5;

    public GameObject m_Player;

    public ExternalBehavior externalBehaviorTree;
    Stack<ExternalBehavior> externalPool;
    private int index;

    public void Awake()
    {
        // Instantiate five External Behavior Tree which will be reused. The Init method will deserialize the External Behavior Tree.
        externalPool = new Stack<ExternalBehavior>();
        for (int i = 0; i < 20; i++)
        {
            ExternalBehavior temp = Object.Instantiate(externalBehaviorTree);
            temp.Init();
            externalPool.Push(temp);
        }
    }

    private void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            Transform zombie = GameObject.Instantiate(SpawnZombiePrefab);
            ZombieBehavior zb = zombie.GetComponent<ZombieBehavior>();
            zb.Target = m_Player;

            zb.m_BehaviorTree.DisableBehavior();
            zb.m_BehaviorTree.ExternalBehavior = externalPool.Pop();
            zb.m_BehaviorTree.EnableBehavior();
         
        }
    }
}

Is this code rigth usage?
I don't want performance spike in the profiler.

Can you show me the correct usage source code?

Thank you.
 
Top