How to use FixedUpdate?

Passero

New member
I have an action that applies forces to rigidbodies so I guess I need to apply that in the OnFixedUpdate instead of the OnUpdate.

Following code doesn't give me my expected behavior:

C#:
public override void OnFixedUpdate()
    {
        bool done = UpdateAction();
        if (done)
            status = TaskStatus.Success;
        else 
            status = TaskStatus.Running;
    }

    public override TaskStatus OnUpdate()
    {
       
        return status;
    }

But following code does give me my expected behavior:

C#:
public override void OnFixedUpdate()
    {
     
    }

    public override TaskStatus OnUpdate()
    {
        bool done = UpdateAction();
        if (done)
            status = TaskStatus.Success;
        else
            status = TaskStatus.Running;
        return status;
    }

So I was wondering how I could put the code in FixedUpdate so I am sure my physics stuff is done correctly.
 
Does OnFixedUpdate get called? I can't see anything wrong with what you are doing in the first example.
 
Yes it's called.
I noticed it acts weird like this because I didn't initialize status in the beginning. I had:

private TaskStatus status;

which was causing the havoc. When I replaced it with
private TaskStatus status = TaskStatus.running;

It was better.
 
Top