zllangct / ecs

A Go-implementation of the ECS (Entity-Component-System), focus on the development of game server.
BSD 3-Clause "New" or "Revised" License
132 stars 10 forks source link

Invalid Component Type error #16

Open cchandel opened 1 year ago

cchandel commented 1 year ago

Hi, I'm converting older code to the new ECS code.

I had a component like so

type Position struct {
    ecs.Component[Position]
    x float64
    y  float64
    routex  []float64
}

func (m *MoveSystem) Init(si ecs.SystemInitConstraint) {
    m.SetRequirements(si, &components.Position{})
}

When registering this system like so

ecs.RegisterSystem[systems.MoveSystem](utilities.World)

I'm getting errors like

panic: invalid component type

goroutine 20 [running]:
github.com/zllangct/ecs.(*Component[...]).check(0xc0001e8ea0?, {0xc0003243e0})
        /home/cc/ecs/component.go:253 +0xf8
github.com/zllangct/ecs.(*System[...]).setRequirements(0xc0001ba5a0, {0x40f507}, {0xc0000af220?, 0x4?, 0x203001})
        /home/cc/ecs/system.go:186 +0xf1
github.com/zllangct/ecs.(*System[...]).SetRequirements(0x17?, {0xc0003243e0?}, {0xc0000af220, 0x2a?, 0xca0e80?})
        /home/cc/ecs/system.go:161 +0x2d
ecs-server/systems.(*MoveNpcSystem).Init(0xc0001ba5a0, {0xc000100000?})
        /home/cc/ecs-server/systems/moveSystem.go.go:34 +0x112

Seems like there's an issue using slices in components. Please help.

zllangct commented 1 year ago
type Position struct {
    ecs.Component[Position]
    x float64
    y  float64
    routex  [3]float64
}

Component's member "routex" should be value type, you can use array replace ths slice, routex []float64 -> routex [3]float64