Adding a Sprite reference in the localization table makes the value not visible from the inspector m

Hello,

I’ve created an asset table called ‘Posters’ with some entries. Each entry is referencing a sprite. In my scriptable object I have a field for referencing a certain entry, like so:

[SerializeField] private LocalizedSprite _poster;

I have an issue when trying to set the references in the inspector. As long as I haven’t added an object into the locale column, I can access the entries in the inspector fine.
Everything looks good

However, if I add a sprite reference to one or both locales, the entry for which I’ve added the sprite reference is no longer available in the inspector.
Notice, the MODULE_POSTER_MAGNETISM is no longer available in the inspector

There is however a workaround to get this to work via the inspector:

  1. Choose the scriptable object where you want to add the LocalizedSprite reference.
  2. Collapse the reference.
  3. Choose the Table Collection (or create a new one).
  4. Add Table Entry.
  5. Fill out Entry Name.
  6. Add the sprite references.
  7. Ctrl+S to save and the Localization Tables tab will update as well.
  8. Notice that you can now use this entry everywhere.
    Workaround

I’ve noticed 2 things that might hint at what is wrong.

  1. In my script I have the variable type LocalizedSprite, which expects a LocalizedAsset with Sprite as the generic type.
  2. In the second image, notice that once I’ve added one sprite to the English locale column, the second locale column expects a Texture 2D and not a sprite. And this is probably why the entry is not seen in the inspector. It expects a Sprite and not a Texture 2D.
  3. In the third image (step 6 of the workaround), note that once I’ve added the English locale sprite, the expected sprite in the inspector correctly shows Sprite.
  4. The referenced .jpg Texture Type is set to Sprite (2D and UI), so this should be correct.

The issue seems to be that when adding images to locales via the Localization Tables window, it marks them as Texture 2D instead. Doing this via the inspector however, marks them correctly.

Unity: 2021.1.25f1
Addressables: 1.19.9
Localization: 1.0.4

Any ideas what might be the issue or how to work around this? Am I doing something incorrectly?

Thanks!

I just realized I need to drag and drop the sub-object in the project.
7603492--943951--upload_2021-10-26_15-19-52.png

If I drag and drop the parent object it treats it as Texture 2D but if I drag and drop the child object, it works fine.
If I’ve marked the import setting as a sprite then shouldn’t it treat it as a sprite rather than Texture2D?

1 Like

It’s how the sprite asset is treated by unity. A sprite is a Texture asset that has a sprite as a sub asset. So dragging the root treats it as a texture. We could check if the asset has a sprite as a sub asset but decided against it as you may actually want the texture.
Doing it through the localized string inspector should work fine though as we filter by type.

1 Like

Yeah, if you treated it as a Sprite instead of a Texture2D then there wouldn’t be a way to add it as a Texture2D into the localization table. So functionality would be lost.

However, it was very confusing. Perhaps there could be some form of UX improvement to be made here? When drag and dropping a Texture2D, if it is set to be a sprite in the import settings, perhaps a pop-up to ask the user what they want to use it as: Texture2D or a Sprite.

2 Likes

Yeah that’s a good idea. I’ll add it to our UX review

1 Like