ecs icon indicating copy to clipboard operation
ecs copied to clipboard

Invalid Component Type error

Open cchandel opened this issue 3 years ago • 1 comments

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.

cchandel avatar Oct 20 '22 07:10 cchandel

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

zllangct avatar Oct 20 '22 08:10 zllangct