News Forums RAIN General Discussion and Troubleshooting AIRig.Update Takes More Than 10 to 15%

This topic contains 22 replies, has 3 voices, and was last updated by  Sigil 11 months, 1 week ago.

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #39458

    aqib sadiq
    Participant

    I am using Rain AIFor quite a While.I am Facing a problem that AIRIG is taking 10 to 15% in Profiler.I am Developing for Mobile Platforms so 10 to 15% is not Affordable For Me.Please Help

    I am using Behaviour Trees For Movement Purposes.I have 5 to 10 Characters in the Scene

    How Can i Optimize it.

    i am using Random Points and When a character Reaches a Certain Distance to next Point it will assign TARGET variable in Working Memory of that AI to move towards that new point.That all i am doing and it is taking 10 to 15% in Profiler

    Please Help

    • This topic was modified 1 year, 2 months ago by  aqib sadiq.
    #39461

    aqib sadiq
    Participant

    This is The Code I am Using

    public class StartSwimming : MonoBehaviour
    {
        // Use this for initialization
        Animator anim;
        Refrences Data;
        int RandomNumber;
        public AIRig Rig;
        bool OnLand;
        [HideInInspector]
        public bool DontRunChildTrigger;
        void Awake()
        {
            Data = GameObject.FindObjectOfType<Refrences>();
            anim = GetComponent<Animator>();
            if (!Rig)
            {
                Rig = GetComponentInChildren<AIRig>();
            }
            //Rig.AI.Senses.DisableSensor(“BigEye”);
        }
        // Update is called once per frame
        void FixedUpdate()
        {
            if (OnLand)
            {
                if (Vector3.Distance(transform.position, Data.RunningPoints[RandomNumber].transform.position) < 2)
                {
                    GenrateRandomPath();
                }
            }
        }
        void OnCollisionEnter(Collision collide)
        {
            if (collide.gameObject.CompareTag(“Water”))
            {
                anim.SetBool(“Swim”, true);
                GenrateRandomPath();
                Rig.AI.WorkingMemory.SetItem<bool>(“UnderAttack”, true);
                //Rig.AI.WorkingMemory.SetItem<float>(“Speed”,3.0f);
                //Rig.AI.Senses.EnableSensor(“BigEye”);
                //Rig.AI.Senses.GetSensor(“BigEye”).IsActive=true;
            }
            if (collide.gameObject.CompareTag(“Land”))
            {
                GenrateRandomPath();
                //Rig.AI.Senses.EnableSensor(“BigEye”);
                //anim.SetBool(“Run”,true);
                anim.SetBool(“Swim”, false);
                Rig.AI.WorkingMemory.SetItem<bool>(“OnLand”, true);
                OnLand = true;
            }
        }
        public void GenrateRandomPath()
        {
            RandomNumber = Random.Range(0, Data.RunningPoints.Length);
            Rig.AI.WorkingMemory.SetItem<GameObject>(“Target”, Data.RunningPoints[RandomNumber]);
        }
    }
    • This reply was modified 1 year, 2 months ago by  aqib sadiq.
    • This reply was modified 1 year, 2 months ago by  Sigil. Reason: formatting
    #39467

    Sigil
    Keymaster

    So, your code isn’t likely causing issues, otherwise it would have probably been showing up on the profiler instead of AIRig.Update.

    So when you do the profiling, make sure you have Deep Profiling turned off, as this will give a false sense of timing due to the overhead of profiling the behavior tree, at least that has been my experience. At that point, if you could get me a screen shot of the profiler showing the problem you describe, with the profiler foldout opened so we can see if there is any particular part of the AIRig getting hit (like GC alloc vs physics or similar).

    #39476

    aqib sadiq
    Participant
    • This reply was modified 1 year, 2 months ago by  aqib sadiq.
    • This reply was modified 1 year, 2 months ago by  aqib sadiq.
    #39479

    aqib sadiq
    Participant

    Deep Profiling is already Turned off

    This is The Behaviour Tree i am Using


    https://drive.google.com/open?id=0BwACGkvclpC3Z2VWa1ZjMXhOc0k

    These are Some SnapShots of Profiler


    https://drive.google.com/open?id=0BwACGkvclpC3NmgyRDB0Ti13Nms

    https://drive.google.com/open?id=0BwACGkvclpC3dkl2N2RKM1hVXzg

    https://drive.google.com/open?id=0BwACGkvclpC3TUU5czBUWVpfVzA

    • This reply was modified 1 year, 2 months ago by  aqib sadiq.
    • This reply was modified 1 year, 2 months ago by  aqib sadiq.
    • This reply was modified 1 year, 2 months ago by  aqib sadiq.
    • This reply was modified 1 year, 2 months ago by  aqib sadiq.
    #39484

    aqib sadiq
    Participant

    I am Also Facing Another problem
    I am Using Mechanim For Animations.
    But Some Times Behaviour Tree is Unable to Set the Parameter for animator.(Using Mecparam in Rain AI Behaviour Tree)
    Behaviour tree is Showing at run time that Parameter is getting true but it wont effect in animator
    I even turned Mecparam to FOREVER,Util Success but same problem is still occurring.

    Please Reply Fast I really Dont have much time.

    #39487

    Sigil
    Keymaster

    So, for your profiling question. From the looks of it you are seeing fairly normal results. It doesn’t look like the AI is taking an excessive amount of time in any of those frames. The 30/15% looks alarming at first, but the actual MS taken is pretty small.

    That said, if you’d like to squeeze even more out of it, avoid the constraints in your behavior tree as they are evaluated every frame even while children are running. I couldn’t see what the constraints were but given the detect and everything there, likely this is a detect and chase setup. Try something like this instead:

    root
       sequencer
          parallel (succeed: any, fail: any, tie breaker: fail)
             detect (repeat: until success, form variable: _target)
             move (move target variable: _home)
          sequencer
             expression (expression: _target != null)
             parallel (succeed: any, fail: any, tie breaker: fail)
                detect (repeat: until failure, form variable: _target)
                move (move target variable: _target)

    Or at least something like that. That should be a lot faster (relatively speaking).

    As for your other problem, if you accidentally misspelled the variable/trigger you want to set, you would see a large number of warnings in the console (unless you turned the animator warnings off). If you show me how you have your mecparam nodes set and how the animator is setup (parameters in particular) I might see a clue.

    Sorry for the late reply, I was out of town this last week and it takes me a second to get back going.

    #39498

    aqib sadiq
    Participant

    Spelling and every thing is correct in mecparam as shown in image below

    https://drive.google.com/file/d/0BwACGkvclpC3THRwdkE3anltR2s/view?usp=sharing

    Here is snapshot of Animator Controller i am using

    https://drive.google.com/file/d/0BwACGkvclpC3MmZtdXpsVS1Kcm8/view?usp=sharing

    Problem is that it run that part of behviour tree in which i assign some thing to mecparam but it didn’t take effect in the animator and if i pause the game and than resume(Pause and Resume of unity Editor) then it start working well.
    i do not know why this is happening.

    #39499

    aqib sadiq
    Participant

    Yes it is a detect and chase setup.

    In The Behavour tree above You are using DETECT more than once.Is it Right to use DTECTE so many times because too many detects can also cause More CPU time.

    if it is taking a small amount of CPU then Why it is showing more than 15% On profiler

    and please tell me how much CPU Rain AI takes.
    I am using 5 characters in the scene with almost same AI.
    i am getting between 5 to 25% normally.more than 25% and less than 5% is rare.

    and Thanks For Your Help Looking Forward to your feedback

    • This reply was modified 1 year, 1 month ago by  aqib sadiq.
    • This reply was modified 1 year, 1 month ago by  aqib sadiq.
    #39506

    Sigil
    Keymaster

    When trying to optimize a behavior tree I would look at what occurs in the tree when it is executed on a particular frame. It doesn’t matter if I have 100 detects in my tree if the AI never gets to them. So if we break down the execution of the two trees, given the two cases that happen the most (waiting and chasing) this is what you get:

    // original when waiting
    - detect (normal)
    - constraint (expression evaluate)
    - move
    // original when chasing
    - detect (fast)
    - constraint (expression evaluate)
    - move
    // new one when waiting
    - detect (normal)
    - move
    // new one when chasing
    - detect (fast)
    - move

    I only listed the particular nodes that do any significant amount of work on those frames. You can see that the original tree does the exact same thing but has one additional expression evaluation, which has some cost and also some garbage collection. I marked some of the detects as (fast) because if “consistent” is marked true the detect node only has to check to see that the target is still within range.

    So there may be some confusion here, as you keep referring to the CPU % used as an indicator of how expensive your AI is, but CPU % is completely dependent on how expensive your scene is. If your AI is consistent (same simple behavior) the reason you are seeing the AI vary from 5% to greater than 25% is not because your AI is getting more expensive, but more likely because the rest of your scene is getting less expensive. If your scene took only 2ms of CPU time you’d be seeing the AI using greater than 50% of your CPU, but your framerate would be something like 500fps.

    If that’s already clear, I apologize, it just seems we are focusing on a percent that doesn’t really indicate absolute performance, but relative. If we look at the time used instead, things become clearer. In two of the screen shots (the last one was private) the AI used about 1.3ms of CPU time, and if the CPU and AI were the only things we cared about that would be around 770fps. That could be better, but it definitely isn’t slowing the rest of the game down at this point.

    Was there a particular reason you started focusing on the AI though? Aside from being at the top of the profiling list, were you having troubles with your framerate? There does appear to be several GC collections in your profiler screen shot that might be causing a hitch every so often in your framerate. If you are having hitches this could be another issue altogether and we can try to address that instead of trying to squeeze every last frame out of the behavior tree.

    We can try to fix the animator issue after this.

    #39509

    aqib sadiq
    Participant

    Firstly thanks For detailed Feedback.

    ok I Understand that Percentage that AI is taking is varies with Scene.Right?

    and yes i am having FPS Issues.I Post this Issue in Here because i am getting low FPS on Device.

    But Here i Have a question that When We don’t have any AI included in our project at that time we were getting around 35 FPS on A motorola Device(Mobile) but after including AI FPS drops to 15 to 20.

    Here is Image of Profiler in Which There is 78% GC under AIRIG.Update.

    https://drive.google.com/file/d/0BwACGkvclpC3VHpLX3luakdpYkU/view?usp=sharing

    as Show in Image How can i remove that Hitch Which is occurring because of garbage Collection under AIRIG.Update.

    #39510

    aqib sadiq
    Participant

    Regarding Behaviour Tree i am having problem with understanding that without constraints how i am gonna use Make a Character Do the Following.

    A Character is Walking on a path.

    But When a certain Object enters in its Visual Sensor i want that Character to Run on another path.
    and when that certain object Exit its visual sensor it will start walking back on its original path.

    How is that Possible without using Constraints in behaviour Tree as you said that Constraints are Checked Every frame.

    if it is Possible then Please send me a Dummy Image a Behaiour Tree With the requirement i need.

    • This reply was modified 1 year, 1 month ago by  aqib sadiq.
    #39512

    Sigil
    Keymaster

    So on the first problem with the hitching, send me an email to sigil@rivaltheory.com and reference this forum post. I’ll get you a newer build of RAIN that has quite a few optimizations in it that should at least lessen the GCs. I can’t guarantee they’ll go away completely, but in the tests I did they got a lot better.

    So I usually write my behavior trees in a pseudo code as that way I can give you what all the variables I’m using are:

    root
       sequencer
          parallel (succeed: any, fail: any, tie breaker: fail)
             detect (repeat: until success, aspect: "certainobject", form variable: _target)
             move (move target: _walkingPath, move speed: 2)
          sequencer
             expression (expression: _target != null, returns: evaluate)
             move (move target: _runningPath, move speed 4)

    So I interpreted your requirements pretty literally. This walks along along one path target until it reaches the end or detects a “certainobject” aspect in its sensors. The second it detects that object it starts moving to another path target. You could change this to waypoint patrols instead, and it may make more sense:

    root
       sequencer
          parallel (succeed: any, fail: any, tie breaker: fail)
             detect (repeat: until success, aspect: "certainobject", form variable: _target) 
             waypoint patrol (waypoint route: "Patrol Route", loop type: loop, move target variable: _pathTarget)
                move (move target: _pathTarget, move speed: 2)
          waypoint patrol (waypoint route: "Alarm Route", loop type: loop, move target variable: _pathTarget)
             move (move target: _pathTarget, move speed: 4)

    This one would patrol the waypoint patrol route called “Patrol Route” until it detects the aspect “certainobject” and then it would patrol the waypoint patrol route called “Alarm Route”. This one doesn’t even need the expression, as it isn’t possible to reach the second waypoint patrol unless that detect succeeds (assuming the first patrol didn’t fail completely at least).

    Let me know if you have any questions (aside from the email).

    #39514

    aqib sadiq
    Participant

    I am also getting another problem that some times object on which AI is applied does not Move(means Cover Distance)(Move in Behaviour Tree) Even though That part of behaviour tree is running.
    Means Some times it Plays the animation right and do not cover distance and some times it cover distance but do not play the animation and some times it works perfectly well

    This is The Behaviour Tree

    https://drive.google.com/file/d/0BwACGkvclpC3Z2VWa1ZjMXhOc0k/view?usp=sharing

    #39516

    aqib sadiq
    Participant

    I Have Send You the Email as You Told me and i am going to implement the behaviour tree which you defined above.

    Looking Forward For your Feedback on Animator and Movement problem which i defined above(Reply#39514).

Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic.