Is there no way to list all components attached to...
# korge
j
Is there no way to list all components attached to a view?
d
What do you want to achieve with that/what's your use-case?
j
Let's say I have 2 views shipA and shipB. I add some
FollowComponent
to shipA that tells it to follow shipB. Later something changes and I want to do
shipA.getComponent<FollowComponent>().target = shipC
I have that implemented this way, but it seemed a bit hacky...
Copy code
inline fun <reified T : Component> BaseView.getComponent(): T {
    return getOrCreateComponentOther<T> { error("No component of type ${T::class.simpleName}") }
}
d
So you don't need to iterate all the components, but to get a component that should be existing already, or throw an exception if it is not the case, right?
j
Correct (for my specific case)