Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observers don't trigger for override components #1413

Closed
nimble0 opened this issue Oct 26, 2024 · 1 comment
Closed

Observers don't trigger for override components #1413

nimble0 opened this issue Oct 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@nimble0
Copy link
Contributor

nimble0 commented Oct 26, 2024

Describe the bug
Observers don't trigger for override components added from a prefab. Behaviour is as expected in v3.2.11.

To Reproduce
Edited flecs/examples/cpp/prefabs/src/main.cpp

#include <basics.h>
#include <iostream>


struct Defense {
	double value;
};

struct Armour {
	double value;
};

int main() {
	flecs::world ecs;

	// inherited components trigger observer
	//ecs.component<Defense>().add(flecs::OnInstantiate, flecs::Inherit);
	//ecs.component<Armour>().add(flecs::OnInstantiate, flecs::Inherit);

	ecs.observer<const Defense, Armour>("CalculateArmour")
		.event(flecs::OnSet)
		.each([&](const Defense& defense, Armour& armour)
		{
			armour.value = 1.0 / defense.value;
			std::cout << "observer trigger\n";
		});

	// Create a SpaceShip prefab with a Defense component.
	std::cout << "make prefab\n";
	flecs::entity SpaceShip = ecs.prefab("SpaceShip")
		.set<Defense>({ 50 })
		.set(Armour{});

	// Create a prefab instance
	std::cout << "make prefab instance\n";
	flecs::entity inst = ecs.entity("my_spaceship").is_a(SpaceShip);

	// calling modified triggers the observer as expected
	//inst.modified<Armour>();
}

Expected output (v3.2.11)

make prefab
make prefab instance
observer trigger

Actual output

make prefab
make prefab instance

@SanderMertens
Copy link
Owner

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants