Skip to main content
added 132 characters in body
Source Link

I have loaded a 2D sprite from the filesystem and created a sprite from it, which I then attach to a SpriteRenderer. The game object appears in the scene but for some reason it doesn't seem to be using the sprite I loaded, and is instead using the Standard Assets/2D/Materials/SpriteLift sprite. I have attached my sprite creation code and some screenshots:

public static Sprite LoadSprite(string relPath) {
    var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

    // Download texture from file location and resize it
    var www = new WWW (fileUrl);
    var texture = www.texture;
    texture.Resize (textureSize, textureSize);
    texture.name = relPath;
    Debug.Log (texture);

    // Make the sprite
    var sprite = Sprite.Create (texture, spriteRect, spritePivot, textureSize);
    sprite.name = relPath;
    return sprite;
}

The Unity scene with the incorrect sprite: enter image description here

The desired texture: enter image description here

The code that creates the game object and attaches the loaded sprite to the SpriteRenderer:

GameObject go = new GameObject ();
go.name = "Tile_ " + tile.location.ToString();
go.transform.position = tile.location.ToVector3 ();
go.transform.SetParent (this.transform, true);
SpriteRenderer sr = go.AddComponent<SpriteRenderer> ();
sr.sprite = tile.Type.sprite;
sr.enabled = true;

Note that the screenshot contains many game objects all with the same sprite, that's why it looks big in the scene.

EDIT: The problem may be due to materials.

EDIT 2: Screenshot of a selected tile:

enter image description here

I have loaded a 2D sprite from the filesystem and created a sprite from it, which I then attach to a SpriteRenderer. The game object appears in the scene but for some reason it doesn't seem to be using the sprite I loaded, and is instead using the Standard Assets/2D/Materials/SpriteLift sprite. I have attached my sprite creation code and some screenshots:

public static Sprite LoadSprite(string relPath) {
    var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

    // Download texture from file location and resize it
    var www = new WWW (fileUrl);
    var texture = www.texture;
    texture.Resize (textureSize, textureSize);
    texture.name = relPath;
    Debug.Log (texture);

    // Make the sprite
    var sprite = Sprite.Create (texture, spriteRect, spritePivot, textureSize);
    sprite.name = relPath;
    return sprite;
}

The Unity scene with the incorrect sprite: enter image description here

The desired texture: enter image description here

The code that creates the game object and attaches the loaded sprite to the SpriteRenderer:

GameObject go = new GameObject ();
go.name = "Tile_ " + tile.location.ToString();
go.transform.position = tile.location.ToVector3 ();
go.transform.SetParent (this.transform, true);
SpriteRenderer sr = go.AddComponent<SpriteRenderer> ();
sr.sprite = tile.Type.sprite;
sr.enabled = true;

Note that the screenshot contains many game objects all with the same sprite, that's why it looks big in the scene.

EDIT: The problem may be due to materials.

I have loaded a 2D sprite from the filesystem and created a sprite from it, which I then attach to a SpriteRenderer. The game object appears in the scene but for some reason it doesn't seem to be using the sprite I loaded, and is instead using the Standard Assets/2D/Materials/SpriteLift sprite. I have attached my sprite creation code and some screenshots:

public static Sprite LoadSprite(string relPath) {
    var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

    // Download texture from file location and resize it
    var www = new WWW (fileUrl);
    var texture = www.texture;
    texture.Resize (textureSize, textureSize);
    texture.name = relPath;
    Debug.Log (texture);

    // Make the sprite
    var sprite = Sprite.Create (texture, spriteRect, spritePivot, textureSize);
    sprite.name = relPath;
    return sprite;
}

The Unity scene with the incorrect sprite: enter image description here

The desired texture: enter image description here

The code that creates the game object and attaches the loaded sprite to the SpriteRenderer:

GameObject go = new GameObject ();
go.name = "Tile_ " + tile.location.ToString();
go.transform.position = tile.location.ToVector3 ();
go.transform.SetParent (this.transform, true);
SpriteRenderer sr = go.AddComponent<SpriteRenderer> ();
sr.sprite = tile.Type.sprite;
sr.enabled = true;

Note that the screenshot contains many game objects all with the same sprite, that's why it looks big in the scene.

EDIT: The problem may be due to materials.

EDIT 2: Screenshot of a selected tile:

enter image description here

added 50 characters in body
Source Link

I have loaded a 2D sprite from the filesystem and created a sprite from it, which I then attach to a SpriteRenderer. The game object appears in the scene but for some reason it doesn't seem to be using the sprite I loaded, and is instead using the Standard Assets/2D/Materials/SpriteLift sprite. I have attached my sprite creation code and some screenshots:

public static Sprite LoadSprite(string relPath) {
    var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

    // Download texture from file location and resize it
    var www = new WWW (fileUrl);
    var texture = www.texture;
    texture.Resize (textureSize, textureSize);
    texture.name = relPath;
    Debug.Log (texture);

    // Make the sprite
    var sprite = Sprite.Create (texture, spriteRect, spritePivot, textureSize);
    sprite.name = relPath;
    return sprite;
}

The Unity scene with the incorrect sprite: enter image description here

The desired texture: enter image description here

The code that creates the game object and attaches the loaded sprite to the SpriteRenderer:

GameObject go = new GameObject ();
go.name = "Tile_ " + tile.location.ToString();
go.transform.position = tile.location.ToVector3 ();
go.transform.SetParent (this.transform, true);
SpriteRenderer sr = go.AddComponent<SpriteRenderer> ();
sr.sprite = tile.Type.sprite;
sr.enabled = true;

Note that the screenshot contains many game objects all with the same sprite, that's why it looks big in the scene.

EDIT: The problem may be due to materials.

I have loaded a 2D sprite from the filesystem and created a sprite from it, which I then attach to a SpriteRenderer. The game object appears in the scene but for some reason it doesn't seem to be using the sprite I loaded, and is instead using the Standard Assets/2D/Materials/SpriteLift sprite. I have attached my sprite creation code and some screenshots:

public static Sprite LoadSprite(string relPath) {
    var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

    // Download texture from file location and resize it
    var www = new WWW (fileUrl);
    var texture = www.texture;
    texture.Resize (textureSize, textureSize);
    texture.name = relPath;
    Debug.Log (texture);

    // Make the sprite
    var sprite = Sprite.Create (texture, spriteRect, spritePivot, textureSize);
    sprite.name = relPath;
    return sprite;
}

The Unity scene with the incorrect sprite: enter image description here

The desired texture: enter image description here

The code that creates the game object and attaches the loaded sprite to the SpriteRenderer:

GameObject go = new GameObject ();
go.name = "Tile_ " + tile.location.ToString();
go.transform.position = tile.location.ToVector3 ();
go.transform.SetParent (this.transform, true);
SpriteRenderer sr = go.AddComponent<SpriteRenderer> ();
sr.sprite = tile.Type.sprite;
sr.enabled = true;

Note that the screenshot contains many game objects all with the same sprite, that's why it looks big in the scene.

I have loaded a 2D sprite from the filesystem and created a sprite from it, which I then attach to a SpriteRenderer. The game object appears in the scene but for some reason it doesn't seem to be using the sprite I loaded, and is instead using the Standard Assets/2D/Materials/SpriteLift sprite. I have attached my sprite creation code and some screenshots:

public static Sprite LoadSprite(string relPath) {
    var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

    // Download texture from file location and resize it
    var www = new WWW (fileUrl);
    var texture = www.texture;
    texture.Resize (textureSize, textureSize);
    texture.name = relPath;
    Debug.Log (texture);

    // Make the sprite
    var sprite = Sprite.Create (texture, spriteRect, spritePivot, textureSize);
    sprite.name = relPath;
    return sprite;
}

The Unity scene with the incorrect sprite: enter image description here

The desired texture: enter image description here

The code that creates the game object and attaches the loaded sprite to the SpriteRenderer:

GameObject go = new GameObject ();
go.name = "Tile_ " + tile.location.ToString();
go.transform.position = tile.location.ToVector3 ();
go.transform.SetParent (this.transform, true);
SpriteRenderer sr = go.AddComponent<SpriteRenderer> ();
sr.sprite = tile.Type.sprite;
sr.enabled = true;

Note that the screenshot contains many game objects all with the same sprite, that's why it looks big in the scene.

EDIT: The problem may be due to materials.

I have loaded a 2D sprite from the filesystem and created a sprite from it, which I then attach to a sprite rendererSpriteRenderer. The game object appears in the scencescene but for some reason it doesn't seem to be using the sprite I loaded, and is instead using the Standard Assets/2D/Materials/SpriteLift sprite. I have attached my sprite creation code and some screenshots:

public static Sprite LoadSprite(string relPath) { var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

public static Sprite LoadSprite(string relPath) {
    var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

    // Download texture from file location and resize it
    var www = new WWW (fileUrl);
    var texture = www.texture;
    texture.Resize (textureSize, textureSize);
    texture.name = relPath;
    Debug.Log (texture);

    // Make the sprite
    var sprite = Sprite.Create (texture, spriteRect, spritePivot, textureSize);
    sprite.name = relPath;
    return sprite;
}

The Unity scene with the incorrect sprite: enter image description here

The desired texture: enter image description here

The code that creates the game object and attaches the loaded sprite to the sprite rendererSpriteRenderer:

GameObject go = new GameObject ();
go.name = "Tile_ " + tile.location.ToString();
go.transform.position = tile.location.ToVector3 ();
go.transform.SetParent (this.transform, true);
SpriteRenderer sr = go.AddComponent<SpriteRenderer> ();
sr.sprite = tile.Type.sprite;
sr.enabled = true;

Note that the screenshot contains many game objects all with the same sprite, that's why it looks big in the scene.

I have loaded a 2D sprite from the filesystem and created a sprite from it, which I then attach to a sprite renderer. The game object appears in the scence but for some reason it doesn't seem to be using the sprite I loaded, and is instead using the Standard Assets/2D/Materials/SpriteLift sprite. I have attached my sprite creation code and some screenshots:

public static Sprite LoadSprite(string relPath) { var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

    // Download texture from file location and resize it
    var www = new WWW (fileUrl);
    var texture = www.texture;
    texture.Resize (textureSize, textureSize);
    texture.name = relPath;
    Debug.Log (texture);

    // Make the sprite
    var sprite = Sprite.Create (texture, spriteRect, spritePivot, textureSize);
    sprite.name = relPath;
    return sprite;
}

The Unity scene with the incorrect sprite: enter image description here

The desired texture: enter image description here

The code that creates the game object and attaches the loaded sprite to the sprite renderer:

GameObject go = new GameObject ();
go.name = "Tile_ " + tile.location.ToString();
go.transform.position = tile.location.ToVector3 ();
go.transform.SetParent (this.transform, true);
SpriteRenderer sr = go.AddComponent<SpriteRenderer> ();
sr.sprite = tile.Type.sprite;
sr.enabled = true;

Note that the screenshot contains many game objects all with the same sprite, that's why it looks big in the scene.

I have loaded a 2D sprite from the filesystem and created a sprite from it, which I then attach to a SpriteRenderer. The game object appears in the scene but for some reason it doesn't seem to be using the sprite I loaded, and is instead using the Standard Assets/2D/Materials/SpriteLift sprite. I have attached my sprite creation code and some screenshots:

public static Sprite LoadSprite(string relPath) {
    var fileUrl = "file://D:/Unity Projects/2D-Game/mod/base/textures/" + relPath + ".png";

    // Download texture from file location and resize it
    var www = new WWW (fileUrl);
    var texture = www.texture;
    texture.Resize (textureSize, textureSize);
    texture.name = relPath;
    Debug.Log (texture);

    // Make the sprite
    var sprite = Sprite.Create (texture, spriteRect, spritePivot, textureSize);
    sprite.name = relPath;
    return sprite;
}

The Unity scene with the incorrect sprite: enter image description here

The desired texture: enter image description here

The code that creates the game object and attaches the loaded sprite to the SpriteRenderer:

GameObject go = new GameObject ();
go.name = "Tile_ " + tile.location.ToString();
go.transform.position = tile.location.ToVector3 ();
go.transform.SetParent (this.transform, true);
SpriteRenderer sr = go.AddComponent<SpriteRenderer> ();
sr.sprite = tile.Type.sprite;
sr.enabled = true;

Note that the screenshot contains many game objects all with the same sprite, that's why it looks big in the scene.

Source Link
Loading