0
\$\begingroup\$

Which are the corresponding parameters for rect and pivot in exporting an editor defined sprite, to be re-created using Sprite.Create?

I've tried both .rect and .textureRect for storing the editor defined rect for a sprite and also .pivot, but it seems Sprite.Create is not able to re-create the sprite properly(?)

\$\endgroup\$
2
  • \$\begingroup\$ What sprite are you trying to recreate, how are you trying to recreate it, and how do the results you get differ from what you get in-editor? Show us screenshots and code that demonstrate your problem. \$\endgroup\$
    – DMGregory
    Sep 26 at 11:21
  • \$\begingroup\$ it appears to be a unit mismatch between sprite.pivot and the pivot used in Sprite.Create \$\endgroup\$
    – ina
    Sep 27 at 7:43
0
\$\begingroup\$

It appears that Sprite.Create takes a non-pixel based unit value for pivot and sprite.pivot is a pixel based unit.

For example, sprite.pivot for a (1000x500) image would be (500,250) but Sprite.Create wants (0.5,0.5)

\$\endgroup\$
5
  • \$\begingroup\$ Helpfully, this is explicitly described in the documentation: "The third argument pivot determines what becomes the center of the Sprite. This is a Vector2 relative to the rect where Vector2(0.0f, 0.0f) is the bottom left and Vector2(1.0f, 1.0f) is the top right." \$\endgroup\$
    – DMGregory
    Sep 27 at 11:14
  • \$\begingroup\$ sprite.pivot should be in the same units \$\endgroup\$
    – ina
    Sep 28 at 8:24
  • \$\begingroup\$ Not according to the documentation: "Location of the Sprite's center point in the Rect on the original Texture, specified in pixels" \$\endgroup\$
    – DMGregory
    Sep 28 at 11:49
  • \$\begingroup\$ well, this discrepancy is quite annoying \$\endgroup\$
    – ina
    Sep 30 at 0:28
  • \$\begingroup\$ Don't forget to mark your answer as Accepted if it worked for you. \$\endgroup\$
    – DMGregory
    Oct 27 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.