Yurii Zabotkin
Yurii Zabotkin

Reputation: 1

Unity 3d. The sprite copy has a different size under the same conditions

Let me rephrase the question. It seems that because I didn't phrase it well, no one can understand and help with this issue.

I have several objects with Sprite Renderers in my scene. For example, let's take two of them: "bottles" and "box."

When they are just in the scene, they look fine.

When the application starts, I get an asset bundle and insert the sprites from it into the sprite renderers in the scene. After that, the "bottles" object looks fine, but for some reason, the "box" object becomes smaller.

This is not related to 'pixels per unit'; they are identical both before and after the application starts. Overall, the sprites and objects are completely identical, but they behave very differently.

I would appreciate it if someone could point me in the right direction. I've tried everything I could think of.

Result
How it should be

How i get sprite

public Sprite GetSprite(string spriteName)
{
    if (_loadedSprites.TryGetValue(spriteName, out var sprite1))
    {
        return sprite1;
    }
    else
    {
        var texture = _currentAssetBundle.LoadAsset<Texture2D>(spriteName);
        var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one * 0.5f, 100f);
        
        sprite.name = $"RM_{spriteName}";
        
        _loadedSprites.Add(spriteName, sprite);

        return sprite;
    }
}

How i set sprite

protected override void SpriteSetter(Sprite sprite)
{
    _spriteRenderer.sprite = sprite;
}

Upvotes: 0

Views: 86

Answers (1)

Yurii Zabotkin
Yurii Zabotkin

Reputation: 1

I found a solution.

In the project, the sprites had the max size set in the import settings. Either Unity was incorrectly processing the new sprites because of this, or the bundle packer was not saving them correctly. The problem was resolved when I set the max size to the maximum value and rebuilt the bundles.

Upvotes: 0

Related Questions