Skip to content
Discussion options

You must be logged in to vote

You can't pass in concrete type for these "generic function types" because they don't have a name. Instead, as long as you don't require capture closures, you can do this:

struct Condition<ConditionName>
{
    name: ConditionName,
    /// This will modify components on the Entity to remove the condition
    pub add_condition: fn(Entity, &mut Commands),
    /// This will modify components on the Entity to apply the condition
    pub remove_condition: fn(Entity, &mut Commands),
    pub applied: bool,
}

The benefit of that approach is that you can have a single system that runs different add/remove logic for each entity.

Depending on the context, you might be better served with something lik…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@ManevilleF
Comment options

Comment options

You must be logged in to vote
2 replies
@mirkoRainer
Comment options

@cart
Comment options

cart Jul 31, 2021
Maintainer

Answer selected by mirkoRainer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants