Open AnderWoche opened 3 hours ago
If I remove the FamilyOnAdd interface, the error does not occur.
Die world.kt datei
private fun updateAggregatedFamilyHooks(family: Family) {
// system validation like in initAggregatedFamilyHooks is not necessary
// because it is already validated before (in initAggregatedFamilyHooks and in add/remove system)
// update family add hook by adding systems' onAddEntity calls after its original world cfg hook
val addSystems = systems.filter { it is IteratingSystem && it is FamilyOnAdd && it.family == family }
val ownAddHook = worldCfgFamilyAddHooks[family] // it crashed here
family.addHook = if (ownAddHook != null) { entity ->
ownAddHook(this, entity)
addSystems.forEach { (it as FamilyOnAdd).onAddEntity(entity) }
} else { entity ->
addSystems.forEach { (it as FamilyOnAdd).onAddEntity(entity) }
}
Can you provide a simple example on how to reproduce it?
In general: it is not a good practice to link systems together. I see you reference a TreasureSystem and a TileMapPathFinderSystem in your EnemyWayWalkerSystem. That is not a good design. Systems should be separate and ideally don't know from each other.
One solution would be to trigger events and a system reacts on that and does its thing. Another solution is to add components/remove components to an entity to trigger a specific other system.
Second: You are modifying the entity configuration within a family add hook (=onAddEntity). I don't know if that works and that might be the problem with the ArrayIndexOutOfBounds, but I am not 100% sure.
Anyway, to track down the issue, please provide a simplified example where that happens. But maybe it solves itself already when you redesign your approach a little bit, keeping the best practices in my mind that I mentioned above.
stackTrace:
The System: