Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

How to make Sprite.OverrideGeometry() work?

Discussion in 'Unity 5 Pre-order Beta' started by ZimM, Feb 11, 2015.

  1. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi everyone!

    From the Unity 5 Beta changelog:
    Has anyone got this method to do anything? No matter how I tried, I'm always getting this error:
    There is no explanation on why it is "not allowed", and the scripting reference page has nothing about this as well.
    I am using this simple script for testing:
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. // Creates a new Sprite that has mesh copied from a different Sprite
    5. public class SpriteMeshReassigner : EditorWindow {
    6.     private Sprite _sprite1;
    7.     private Sprite _sprite2;
    8.  
    9.     [MenuItem("Tools/SpriteMeshReassigner")]
    10.     private static void ShowWindow() {
    11.         GetWindow<SpriteMeshReassigner>(true);
    12.     }
    13.  
    14.     private void OnGUI() {
    15.         _sprite1 = (Sprite) EditorGUILayout.ObjectField("Sprite 1", _sprite1, typeof(Sprite), false);
    16.         _sprite2 = (Sprite) EditorGUILayout.ObjectField("Sprite 2", _sprite2, typeof(Sprite), false);
    17.  
    18.         if (GUILayout.Button("Reassign mesh")) {
    19.             ushort[] sprite1Triangles = _sprite1.triangles;
    20.             Vector2[] sprite1Vertices = _sprite1.vertices;
    21.  
    22.             Sprite newSprite = Sprite.Create(_sprite2.texture, _sprite2.rect, _sprite2.pivot, _sprite2.pixelsPerUnit, 0, SpriteMeshType.Tight);
    23.             newSprite.OverrideGeometry(sprite1Vertices, sprite1Triangles);
    24.             AssetDatabase.CreateAsset(newSprite, "Assets/testSprite.asset");
    25.         }
    26.     }
    27. }

    Any ideas? I really need this for some custom effects that require sprites having exactly the same tight meshes.

    - Serhii
     
  2. zylazla

    zylazla

    Joined:
    Feb 28, 2013
    Posts:
    4
    Probably this doesn't work for you, because you don't have the PRO license
     
  3. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Um, Unity 5 pre-order beta is only available to Pro customers, how could I not have the Pro license?..
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    Tried on rc2, same error..