Page MenuHomeFeedback Tracker

ScriptComponent::OnAddedToParent not firing reliably on entity init
Closed, ResolvedPublic

Description

Depending on if a script component is alphabetically loaded after the Hierarchy component the parent events do not fire. If I rename the component to come first the event works as expected.

This seems to have to do with the init of the hierarchy component that fires off the events to all currently known components. But any components added after do not get the event anymore. Later at runtime when all components are loaded this of course never becomes a problem. But during the creation of the entity the parent change event info needs to be saved and passed into all created script components that come later during init OR the hierarchy information is loaded dead last. The OnAddedToParent should fire reliably no matter which order the components have.

Details

Severity
Major
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce
class TestStuffComponentClass : ScriptComponentClass
{
};

class TestStuffComponent : ScriptComponent
{
	//------------------------------------------------------------------------------------------------
	override protected event void OnPostInit(IEntity owner)
	{
		PrintFormat("TestStuffComponent(%1)", this);
	}
	
	//------------------------------------------------------------------------------------------------
	override event void OnAddedToParent(IEntity child, IEntity parent)
	{
		PrintFormat("OnAddedToParent(%1, %2)", child, parent);
	}

	//------------------------------------------------------------------------------------------------
	override event void OnRemovedFromParent(IEntity child, IEntity parent)
	{
		PrintFormat("OnRemovedFromParent(%1, %2)", child, parent);
	}
};

Entity setup:

and nothing prints.

Renaming the component to ATestStuffComponent makes it work correctly.

SCRIPT : OnAddedToParent(GenericEntity<0x000001E2B206B630>, GenericEntity<0x000001E2B206B030>)
SCRIPT : ATestStuffComponent(ATestStuffComponent<0x000001E2B045BD20>)

Event Timeline

Geez changed the task status from New to Assigned.May 19 2023, 12:45 PM
Geez closed this task as Resolved.May 26 2023, 12:20 PM
Geez claimed this task.
Geez added a subscriber: Geez.

Resolved for 0.9.9.