Skip to content

Editor crash due to Custom Asset with [Display] Attribute without Name set #3149

@Basewq

Description

@Basewq

Release Type: Official Release

Version: All versions up to 4.3.0.2507

Platform(s): Windows (Game Studio)

Describe the bug
Adding a [Display] attribute on a custom asset and not setting the Name property can cause the editor to crash when viewing any asset that references this custom asset.

To Reproduce
Steps to reproduce the behavior:

  1. Create custom asset MyAsset (along with all necessary files) with [Display] attribute without setting Name property.
  2. Create a custom component with MyAsset property.
  3. Create MyAsset, add custom component to a scene then reference MyAsset.
  4. Restart editor, try open the scene -> crash.

Expected behavior
Not crash.

Additional context
Caused by the code:

private void UpdateStats(IEnumerable<AssetViewModel> assets)
{
var typeCounters = assets.GroupBy(a => a.TypeDisplayName).Select(grp =>
{
var count = grp.Count();
return $"{count} {Pluralize(grp.Key, count)}";
});
TypeCountersAsText = string.Join(", ", typeCounters);
}
private static string Pluralize(string word, int count)
{
if (count == 1)
return word;
// exceptions
if (word.ToUpperInvariant() == "ENTITY")
{
return $"{word.Substring(0, word.Length - 1)}es";
}
return $"{word}s";
}

public override string TypeDisplayName { get { var desc = DisplayAttribute.GetDisplay(AssetType); return desc != null ? desc.Name : AssetType.Name; } }

TypeDisplayName will be null, which is used as the 'GroupBy' key then word.ToUpperInvariant() throws a null exception in the Pluralize method.

Workaround
Set Name property on [Display] attribute on custom asset, or remove [Display] attribute. The .sdtpl file is where the actual display metadata should be set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions