Skip to content

Unable to get data of different Entities using GetInterestedComponents #10

Description

@cchandel

Hi,
I've setup a world and added 3 Entities with movement component.

collection.go:34: collection Add:{"Speed":0.008888888888888889,"Course":145}
collection.go:34: collection Add:{"Speed":0.0033333333333333335,"Course":120}
collection.go:34: collection Add:{"Speed":0.0033333333333333335,"Course":45}

I'm trying to use an Input system similar to your example to get and change speed for an entity.

type MoveChange struct {
	ecs.FreeDisposableComponent[MoveChange]
}
import (
	"github.com/zllangct/ecs"
	"astt-server/components"
)

type MoveChangeSystem struct {
	ecs.System[MoveChangeSystem]
}

func (mc *MoveChangeSystem) Init() {
	ecs.AddRequireComponent2[components.Movement, components.MoveChange](mc)
}

func (mc *MoveChangeSystem) PreUpdate(event ecs.Event) {

	iterMovement := ecs.GetInterestedComponents[components.Movement](mc)
	if iterMovement == nil {
		return
	}
	for mov := iterMovement.Begin(); !iterMovement.End(); iterMovement.Next() {
		println(mov.Speed, mov.Course)
		println(mov.Owner().Entity())
	}
}

I get 3 values printed - but they're all the same.

+8.888889e-003 +1.450000e+002
-7673762469411480564

+8.888889e-003 +1.450000e+002
-7673762469411480564

+8.888889e-003 +1.450000e+002
-7673762469411480564

How do I get the data for each separate entity?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions