Skip to content

Adding generic components to an entity #135

Answered by Quillraven
Hellwoodoo asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

the reason is that you are not adding a component type to an entity. You want to add a component itself (an instance of a component). That's why Fleks internally has a function like this (note the component argument instead of component type):

 inline operator fun <reified T : Component<T>> Entity.plusAssign(component: T) {
        val compType: ComponentType<T> = component.type()
        compMasks[this.id].set(compType.id)
        val holder: ComponentsHolder<T> = componentService.holder(compType)
        holder[this] = component
    }

There is also an unsafe version that takes a list of components that might fit your use-case better:

 operator fun Entity.plusAssign(components: List<C…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@Hellwoodoo
Comment options

@Hellwoodoo
Comment options

@Quillraven
Comment options

@Quillraven
Comment options

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