playMaker

Author Topic: set u gui sprite error playmaker[solved]  (Read 488 times)

Ofonna

  • Full Member
  • ***
  • Posts: 230
    • View Profile
set u gui sprite error playmaker[solved]
« on: June 22, 2017, 07:40:49 PM »
hey guy,

i keep getting this error whenever i try to set sprites to a gameobject's image component,

i have an array of type "object" and i'm setting the sprite as object because there's no sprite variable so that works, but when i get to setting the sprite with the "set ugui sprite action " this error pops up.

InvalidCastException: Cannot cast from source type to destination type.

please help,
thanks!
« Last Edit: June 24, 2017, 04:48:30 PM by Carmichael »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 13526
  • Official Playmaker Support
    • View Profile
Re: set u gui sprite error playmaker
« Reply #1 on: June 23, 2017, 12:34:36 AM »
Hi

there is a dedicated action for this, make sur your FsmObject variable is set to UnityEngine.Sprite and it will work fine



is this the action you use?


Bye,

 Jean

Ofonna

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: set u gui sprite error playmaker
« Reply #2 on: June 23, 2017, 10:52:24 AM »
hi Jean, yes , that's the action i used, but i'm updating the variable through an array, like switching sprites, but from my observation, the sprites had to be within a sprite sheet in order to stop that error.

maybe it's something worth checking out. but that was how i solved the issue. (putting my sprites in one sprite sheet)

Broken Stylus

  • Junior Playmaker
  • **
  • Posts: 82
    • View Profile
Re: set u gui sprite error playmaker[solved]
« Reply #3 on: August 01, 2018, 10:28:24 AM »
Necroman strikes again!  8)

Just to say that if you use null as the value for a sprite field or for a FsmObject:sprite, you'll still get the error talked about earlier (wawa CastException wawa...).

So if you need to set sprites to something empty, just create such a sprite (2 x 2 pixels for example) with an alpha of 0 and add it to your sprite sheet, then use that "empty" sprite instead of null.

Also, don't forget that the uGUI image element will keep its former size when you set the image to this empty sprite, so depending on your needs you may need to set your image component to its native size.
Note that there's no no action to do that right now so you'll have to use "Call Method", UnityEngine.UI.Image with "void SetNativeSize ()".



P.S.: might it be possible to have an action on the ecosystem to set a uGUI sprite to its native size? Thx.