How to Resize File-Imported Texture2D/Sprite and how to change Filter, all of this in runtime?

Hello, this could be a complicated topic I want to ask about so here it is. I am creating a game that can basically have modding features by outside code using JSON, and part of it is having textures being imported on to it outside of the game in a directory. The game would be a 2D block “minecraft off-brand” game, and why I add this info is because the blocks will all be Tiles (Note: note the “Tiles” later) and not separate Gameobjects. I have been successful at like detecting .txt files and reading them so what block and what their info was gonna be. But the problem was their textures, if you wanted to make or code a block, you would have to include their texture (which is a 16x16 picture btw). But then as it is imported by code inside unity in my script, the Texture gets small, and I had no way to fix it, here is an example of it:

so here is the code for the import:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class ImageFileManager 
{
    public static readonly string IMAGE_FOLDER = 
    Application.persistentDataPath + "/textures/";
    
    public static Sprite GetCustomImageSprite(JsonBlockClass jsonBlock)
    {
        Sprite sprite = null;
        Texture2D tex;
        
        tex = new Texture2D(16, 16, TextureFormat.DXT1, false);
        WWW www = new WWW("file:" + IMAGE_FOLDER + 
        jsonBlock.imageName);
        www.LoadImageIntoTexture(tex);
        
        sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), 
        Vector2.zero);
        
        return sprite;
    }
}

Please Help, if anyone could, Thanks.

Hi @fendergame

First of all I think to understand your issue, it would be better to drop some sample project.

My guess is that your problem is not related to the texture or texture import settings.
I think you use different “Pixel Per Unit” for the tile you have in the project, even though it has 16x16 size.

Your texture in the project (the big tile) may have “Pixel Per Unit” set about 20.
But when you create a Sprite, its default “Pixel Per Unit” is 100.

Another thing is the Pivot, which you have set to Vector2.zero.
It seems to me that it should be Vector2(0.5f, 0.5f) in order to be aligned with the one in the project.