-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GC/Performance problems #12
Comments
I guess that your Besides from that your code looks okish. I would suggest writing it like this:
Also note that your task should probably should eventually stop once the target location is reached, so putting another condition in may be good:
Besides from that: If you're designing a "complex" task like that you may also just consider creating an own subclass of Task. |
speed is not the reason, I tried. |
using UnityEngine;
} |
using System;
|
Please forgive my poor English, I am trying my best. |
OMG. I found the reason. |
I think it's better to put the worker functions outside the behavior tree structure, and the behavior tree just only do workflow decision. That‘ll make the behavior tree neat and trim. |
Since separated the heavy functional Action methon outside the behavior tree structure, The core job left is to design the game logic in the tree which gives me a lot of fun.
|
when you create a custom task you don't wrap that inside an
Exactly, that's the way I also do it most of the time. And thanks for the compliment.
That really depends on what you want to achieve and the way you want to do it. I don't know your exact use-case. But from looking at your suggested structure, my feeling is that things like "Camera" or "Music" wouldn't go in a behaviour tree that's used for an Enemy AI, as you probably have multiple instances of that running at the same time. However it could actually make sense for other scenarios, for example if you want to control a your global game state with a BT ( I never used it for such things, but I could think that it could make sense in some scenarios ). Like I said, it really depends, it's hard to give a general advice here. |
Thank you a lot . |
I made a scene of 50 bad guys as NavMeshAgent chased a hero ,when they reached they play some attack animation. At the same time, I check the memory analysis tool, I found the GC Allocation of UnityContext.Update() in BehaviourUpdate is aways 2.3-5k in every second. Will that lead a performance defect? Any possibility to optimize? I have no idea how to solve . I just point it out and I hope that can help you improve the performance. Maybe it's not a issue. |
I have not yet made a game with NPBehave and more than around 5 enemies in the scene, so I did never run into such problems. If there really is a problem we'll have to check how to reduce those allocations. How big is the performance problem you have (how much of a frame's time is spend doing the GC?)? Also note that depending on the game you may think about some kind of "LOD" mechanismn for AI's far away or not visible, meaning you may want to have a system where AI's that are not visible anyway do update much less frequently or even suspend completely. This is a general thing, you also should do that when not using NPBehave. |
I believe there are some performance & GC issues. Also @myselfshj ,,, you can try to use Deep profile,, |
So at least for the Assertions we could either For the problems with the |
I don't think that's a problem. Unity Profiler shows GC Allocations per Frame: 60/2.3 KB. I don't know what's 60 means. When I run the scene CPU value in Profiler Window is about 10ms, that's why I think it's not a problem. Compare to the GUI GCalloc, it's quite low, according to the bad guy number. I am thinking split my scene to severl gamezones, eachone is a small zone. Just like what you said "AI's that are not visible anyway do update much less frequently or even suspend". But I wander how to disable AI tree in script? gameObjec.GetComponent.active = false? |
@MohHeader |
For NPBehave it should be enough to just This is usually sufficient, however if you want to go the more complicated route and freeze the AI in it's current state and resume from the exact same state later, the best would be to build the tree with a custom |
OK,I see. |
No, you don't need to write an own Here is an example that throttles the tree to be updated every second:
you can also share this clock between multiple trees if you like, so you could for example have a group of 10 AIs in a same area driven by the same clock and having 10 other AIs in a different area driven by a different clock in a different speed. I cannot think about how to make that simpler TBH. The current implementation allows you to do whatever you like with little code to write. Although as always I'm open for suggestions. |
Thanks for your kindness. |
Hello Author
I tried to put a method which calls another component function into the mutiframe action,like this:
new Action((bool _shouldCancel) =>
{ if (!_shouldCancel)
{
MoveInComp(true);
return Action.Result.PROGRESS;
} })
The caller method defined like this:
private void MoveInComp(bool isStart)
{
GetComponent().isStart = true;
GetComponent().enemyPos = new Vector3(21f, 2f, 2f);
}
And the really working function is in Update() of MoveComponent component
void Update()
{ if (isStart == true)
MoveTowardsEnemy(enemyPos); }
The running result in Unity is gameObject moved to the targePos just in One frame. My intent is to let it move in multiframe slowly.
How to do it then ?
//////*******//////
So I tried another way.
I didn't use Update() in MoveComponent this time. I just call the plain MoveTowardsEnemy() method.
public void MoveTowardsEnemy() //in MoveComponent
{ if (isStart == true && enemyPos != Vector3.zero)
gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, enemyPos, this.speed); }
In behavior tree caller is like this:
private void MoveInComp(bool isStart)
{
GetComponent().isStart = true;
GetComponent().enemyPos = new Vector3(21f, 2f, 2f);
GetComponent().MoveTowardsEnemy() ;
}
But the result is same, gameObject moved to the targePos just in One frame.
Please give me some advice. Thanks
The text was updated successfully, but these errors were encountered: