Skip to content

FleksNoSuchEntityComponentException: Entity has no component of type 'BComponent'. #125

@ludek17052

Description

@ludek17052

Hello,
Is it a bug or am I doing something wrong?
I add Component (name = BComponent) to Entity and in System class itterating over entities with BComponent is running.
I can check if Entity has a BComponent: entity.has(BComponent) = true
But if I call entity.get(BComponent), it will stops with FleksNoSuchEntityComponentException.

I suppose if "entity.has(BComponent)" is true, then "entity.get(BComponent)" should be not null or Exception.

Output in my console:

CmpSystem One onTickEntity
CmpSystem Two onTickEntity
entity.has(BComponent) = true
Exception in thread "main" com.github.quillraven.fleks.FleksNoSuchEntityComponentException: Entity 'Entity(id=0, version=0)' has no component of type 'BComponent'.

class MOneTest : KtxGame<KtxScreen>() {

    override fun create() {
        addScreen(GameScreen())
        setScreen<GameScreen>()
    }

    override fun render() {
        currentScreen.render(Gdx.graphics.deltaTime)
    }
}

class GameScreen() : KtxScreen {

    private val eWorld = configureWorld {
        systems {
            add(CmpSystemOne())
            add(CmpSystemTwo())
        }
    }

    init {
        eWorld.entity {
            it += AComponent
        }
    }

    override fun render(delta: Float) {
        eWorld.update(delta)
    }
}

class AComponent() : Component<AComponent> {
    override fun type() = AComponent

    companion object : ComponentType<AComponent>()
}

class BComponent() : Component<BComponent> {
    override fun type() = BComponent

    companion object : ComponentType<BComponent>()
}

class CmpSystemOne() : IteratingSystem(World.family { all(AComponent) }) {
    override fun onTickEntity(entity: Entity) {
        println("CmpSystem One onTickEntity")
        entity.configure {
            it += BComponent
        }
    }
}

class CmpSystemTwo() : IteratingSystem(World.family { all(BComponent) }) {
    override fun onTickEntity(entity: Entity) {
        println("CmpSystem Two onTickEntity")
        println("entity.has(BComponent) = " + entity.has(BComponent))
        val bCmp = entity.get(BComponent)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions