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

[Enhancement] RequireComponent Attribute #23

Closed
inmny opened this issue Oct 14, 2024 · 1 comment
Closed

[Enhancement] RequireComponent Attribute #23

inmny opened this issue Oct 14, 2024 · 1 comment

Comments

@inmny
Copy link

inmny commented Oct 14, 2024

It is common to assign RequireComponent for a self-defined component in Unity for easier initialization.

Like this:

class SubComponent : MonoBehaviour {}

[RequireComponent(typeof(SubComponent), typeof(SpriteRenderer))]
class CustomComponent : MonoBehaviour {}

var obj = new GameObject("Test", typeof(CustomComponent));

// Then obj has CustomComponent, SubComponent, SpriteRenderer together.

Is it possible to implement it in Friflo? like this:

[RequireComponent(typeof(Position))] 
struct AnimData : IComponent 
{
    public int frame_idx;
    public Sprite[] ref_frames;
}

var e = store.CreateEntity(new AnimData());
// Then e has both AnimData and Position components.

To my knowledge, it is possible to expand Generic<AnimData>.ComponentTypes through the attribute,

@friflo
Copy link
Owner

friflo commented Jan 11, 2025

Thought about this.
It is possible but doing this has a performance impact on all AddComponent<> and CreatEntity() operations. Whether with or without this attribute.

Additionally understanding of code is more complicated because components may be added implicit.
You now have to check component type attributes when adding them.
Otherwise you will wonder why a component was added without doing this explicit.

@friflo friflo closed this as completed Jan 11, 2025
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