Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Karl_Mamuyac · Mar 28 at 09:02 AM · networkingarrayspritetexture2d

Uploaded sprite can't set bones and poses

I'm trying to get a sprite by uploading a texture using this script :

 IEnumerator UpdatePNG(string path){
         UnityWebRequest pngWR = new UnityWebRequest("file:///" + path);
         DownloadHandlerTexture texDl = new DownloadHandlerTexture(true);
         pngWR.downloadHandler = texDl;
         yield return pngWR.SendWebRequest();
         if (pngWR.result == UnityWebRequest.Result.Success) {
             Texture2D t = texDl.texture;
             Sprite s = Sprite.Create(t, new Rect(0, 0, t.width, t.height), new Vector2(.5f, .5f), 100f, 100, SpriteMeshType.Tight);
 
             pngSwapper.InjectCustom(s);
         }
     }


After uploading, the method calls InjectCustom();

 public void InjectCustom (Sprite customSprite){
         // Duplicate bones and poses
         string referenceLabel = targetResolver.GetLabel();
         Sprite referenceHead =
         spriteLibrary.GetSprite(targetCategory, referenceLabel);
         SpriteBone[] bones = referenceHead.GetBones();
         NativeArray<Matrix4x4> poses = referenceHead.GetBindPoses();
         customSprite.SetBones(bones);
         customSprite.SetBindPoses(poses);
 
         // Inject new sprite
         const string customLabel = "customHead";
         spriteLibrary.AddOverride(customSprite, targetCategory, customLabel);
         targetResolver.SetCategoryAndLabel(targetCategory, customLabel);
         
     }

If the sprite used by InjectCustom() is already in Unity, it'll work and attach itself to the bones but if I use the uploaded sprite it returns this error

 IndexOutOfRangeException: Index -1079236362 is out of range of '1' Length.
 Unity.Collections.NativeArray`1[T].FailOutOfRangeError (System.Int32 index) (at <13e6546058e340ada820e34dce3b245e>:0)
 Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <13e6546058e340ada820e34dce3b245e>:0)
 Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <13e6546058e340ada820e34dce3b245e>:0)
 UnityEngine.U2D.Animation.SpriteSkinUtility.Deform (Unity.Mathematics.float4x4 rootInv, Unity.Collections.NativeSlice`1[T] vertices, Unity.Collections.NativeSlice`1[T] boneWeights, Unity.Collections.NativeArray`1[T] boneTransforms, Unity.Collections.NativeSlice`1[T] bindPoses, Unity.Collections.NativeSlice`1[T] deformed) (at Library/PackageCache/com.unity.2d.animation@7.0.4/Runtime/SpriteSkinUtility.cs:249)
 UnityEngine.U2D.Animation.SpriteSkinUtility.Deform (UnityEngine.Sprite sprite, UnityEngine.Matrix4x4 rootInv, Unity.Collections.NativeSlice`1[T] vertices, Unity.Collections.NativeSlice`1[T] tangents, Unity.Collections.NativeSlice`1[T] boneWeights, Unity.Collections.NativeArray`1[T] boneTransforms, Unity.Collections.NativeSlice`1[T] bindPoses, Unity.Collections.NativeArray`1[T] deformableVertices) (at Library/PackageCache/com.unity.2d.animation@7.0.4/Runtime/SpriteSkinUtility.cs:220)
 UnityEngine.U2D.Animation.SpriteSkinUtility.Deform (UnityEngine.Sprite sprite, UnityEngine.Matrix4x4 invRoot, UnityEngine.Transform[] boneTransformsArray, Unity.Collections.NativeArray`1[T] deformVertexData) (at Library/PackageCache/com.unity.2d.animation@7.0.4/Runtime/SpriteSkinUtility.cs:313)
 UnityEngine.U2D.Animation.SpriteSkin.LateUpdate () (at Library/PackageCache/com.unity.2d.animation@7.0.4/Runtime/SpriteSkin.cs:311)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Karl_Mamuyac · Mar 30 at 02:31 PM

Solved it! I uploaded the png as a file instead and then loaded it through Resource.Load() after calling AssetDatabase.Refresh()

 IEnumerator UploadPNG(string path){
         UnityWebRequest www = UnityWebRequest.Get(path);
         yield return www.SendWebRequest();
 
         if(www.result == UnityWebRequest.Result.ProtocolError){
             Debug.Log(www.error);
         }
         else{
             byte[] bytes = www.downloadHandler.data;
             string fileName = Path.GetFileName(path);
             string fileName2 = Path.GetFileNameWithoutExtension(path);
             string filePath = Path.Combine(Application.dataPath, "Resources/PNGs/" + fileName);
             string filePath2 = Path.Combine("PNGs/" + fileName2);
             File.WriteAllBytes(filePath, bytes);
             Debug.Log("File saved to: " + filePath);
 
             AssetDatabase.Refresh();
             latestUpload = filePath;
             pngSwapper.LoadUploadedSprite(filePath2);
         }
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

228 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sending image data through SyncVar doesn't work (Mirror Networking) 0 Answers

Difference between Sprite and Default texture types? 0 Answers

Checking for overlaping sprites in an array 1 Answer

How to check the current sprite in the image source? Unity 4.6beta20 1 Answer

What's wrong with this script? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges