Prevent Identity.Name NRE exception (#28433)
Fix Identity.Name exception
This commit is contained in:
@@ -21,7 +21,6 @@ using Robust.Client.UserInterface;
|
|||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Shared.Input;
|
using Robust.Shared.Input;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Prototypes;
|
|
||||||
using static Content.Client.Inventory.ClientInventorySystem;
|
using static Content.Client.Inventory.ClientInventorySystem;
|
||||||
using static Robust.Client.UserInterface.Control;
|
using static Robust.Client.UserInterface.Control;
|
||||||
|
|
||||||
@@ -53,9 +52,13 @@ namespace Content.Client.Inventory
|
|||||||
_inv = EntMan.System<InventorySystem>();
|
_inv = EntMan.System<InventorySystem>();
|
||||||
_cuffable = EntMan.System<SharedCuffableSystem>();
|
_cuffable = EntMan.System<SharedCuffableSystem>();
|
||||||
|
|
||||||
|
// TODO update name when identity changes
|
||||||
var title = Loc.GetString("strippable-bound-user-interface-stripping-menu-title", ("ownerName", Identity.Name(Owner, EntMan)));
|
var title = Loc.GetString("strippable-bound-user-interface-stripping-menu-title", ("ownerName", Identity.Name(Owner, EntMan)));
|
||||||
_strippingMenu = new StrippingMenu(title, this);
|
_strippingMenu = new StrippingMenu(title, this);
|
||||||
_strippingMenu.OnClose += Close;
|
_strippingMenu.OnClose += Close;
|
||||||
|
|
||||||
|
// TODO use global entity
|
||||||
|
// BUIs are opened and closed while applying comp sates, so spawning entities here is probably not the best idea.
|
||||||
_virtualHiddenEntity = EntMan.SpawnEntity(HiddenPocketEntityId, MapCoordinates.Nullspace);
|
_virtualHiddenEntity = EntMan.SpawnEntity(HiddenPocketEntityId, MapCoordinates.Nullspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ public static class Identity
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string Name(EntityUid uid, IEntityManager ent, EntityUid? viewer=null)
|
public static string Name(EntityUid uid, IEntityManager ent, EntityUid? viewer=null)
|
||||||
{
|
{
|
||||||
var uidName = ent.GetComponent<MetaDataComponent>(uid).EntityName;
|
var meta = ent.GetComponent<MetaDataComponent>(uid);
|
||||||
|
if (meta.EntityLifeStage <= EntityLifeStage.Initializing)
|
||||||
|
return meta.EntityName; // Identity component and such will not yet have initialized and may throw NREs
|
||||||
|
|
||||||
|
var uidName = meta.EntityName;
|
||||||
|
|
||||||
if (!ent.TryGetComponent<IdentityComponent>(uid, out var identity))
|
if (!ent.TryGetComponent<IdentityComponent>(uid, out var identity))
|
||||||
return uidName;
|
return uidName;
|
||||||
@@ -34,7 +38,7 @@ public static class Identity
|
|||||||
return uidName;
|
return uidName;
|
||||||
}
|
}
|
||||||
|
|
||||||
return uidName + $" ({identName})";
|
return $"{uidName} ({identName})";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user