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

fix: EntityPrototypeView now only creates entity when in opened ui (after EnteredTree and not after ExitedTree) #5491

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ END TEMPLATE-->

### Bugfixes

*None yet*
* EntityPrototypeView control now is creating entity and keeping it alive only when opened (between EnteredTree and ExitedTree).

### Other

Expand Down
29 changes: 20 additions & 9 deletions Robust.Client/UserInterface/Controls/EntityPrototypeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public EntityPrototypeView(EntProtoId? entProto, IEntityManager entMan) : base(e

public void SetPrototype(EntProtoId? entProto)
{
SpriteSystem ??= EntMan.System<SpriteSystem>();

if (entProto == _currentPrototype
&& EntMan.TryGetComponent(Entity?.Owner, out MetaDataComponent? meta)
&& meta.EntityPrototype?.ID == _currentPrototype)
Expand All @@ -32,14 +30,10 @@ public void SetPrototype(EntProtoId? entProto)
}

_currentPrototype = entProto;
SetEntity(null);
EntMan.DeleteEntity(_ourEntity);

if (_currentPrototype != null)
if (_ourEntity != default)
{
_ourEntity = EntMan.Spawn(_currentPrototype);
SpriteSystem.ForceUpdate(_ourEntity.Value);
SetEntity(_ourEntity);
UpdateEntity();
}
}

Expand All @@ -48,12 +42,29 @@ protected override void EnteredTree()
base.EnteredTree();

if (_currentPrototype != null)
SetPrototype(_currentPrototype);
{
UpdateEntity();
}
}

protected override void ExitedTree()
{
base.ExitedTree();
EntMan.TryQueueDeleteEntity(_ourEntity);
}

private void UpdateEntity()
{
SetEntity(null);
EntMan.DeleteEntity(_ourEntity);

if (_currentPrototype != null)
{
SpriteSystem ??= EntMan.System<SpriteSystem>();

_ourEntity = EntMan.Spawn(_currentPrototype);
SpriteSystem.ForceUpdate(_ourEntity.Value);
SetEntity(_ourEntity);
}
}
}
Loading