Skip to content
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

Parallel behaviour should reset children onInitialize #3

Open
AtheMathmo opened this issue Jun 15, 2020 · 1 comment
Open

Parallel behaviour should reset children onInitialize #3

AtheMathmo opened this issue Jun 15, 2020 · 1 comment

Comments

@AtheMathmo
Copy link

Hey!

I've been using this code as a reference and I ran into a small problem. I think that the Parallel behaviour will not reset states correctly for behaviours that terminate (that succeed or fail).

The resetting is left to Behaviour::tick(), which updates the status of the behaviour. But the Parallel behaviour will not tick behaviours that were previously terminated.

One fix is to have Parallel implement onInitialize and reset the children's state there (or tick them, though this wont interact well with the Repeat decorator).

@ljluestc
Copy link

ljluestc commented Jan 4, 2024


class Parallel : public Behavior {
public:
    // Other members and methods...

    void onInitialize() override {
        // Reset or reinitialize the state of all child behaviors
        for (auto& child : children) {
            if (child->getStatus() == BH_SUCCESS || child->getStatus() == BH_FAILURE) {
                child->reset(); // Reset the child behavior if it has terminated
            }
        }
    }

    Status update() override {
        // Implementation of the parallel behavior's update logic...
    }

    // Other members and methods...
};

class Behavior {
public:
    // Other members and methods...

    virtual void onInitialize() {
        // Default implementation of onInitialize, if any
    }

    void reset() {
        status = BH_INVALID;
        onInitialize();
    }

    // Other members and methods...
};

// Other necessary code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants