Skip to content

Commit

Permalink
Immediately track parent components when adding them on child.
Browse files Browse the repository at this point in the history
  • Loading branch information
isadorasophia committed Jul 22, 2024
1 parent 3366c95 commit 478c70f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Bang/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,16 @@ private void NotifyAndSubscribeOnComponentAdded(int index, IComponent c)

OnComponentAdded?.Invoke(this, index);

if (_lookup.IsRelative(index))
if (_lookup.IsRelative(index) && _parent is not null)
{
_parent?.TrackComponent(index, OnParentModified);
_parent.TrackComponent(index, OnParentModified);

if (c is IParentRelativeComponent relativeComponent &&
_parent.TryGetComponent(index, out IComponent? parentComponent))
{
// Immediately place the parent component reference.
relativeComponent.OnParentModified(parentComponent, this);
}
}
}

Expand Down

0 comments on commit 478c70f

Please sign in to comment.