playMaker

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

Ofonna

  • Full Member
  • ***
  • Posts: 230
set u gui sprite error playmaker[solved]
« on: June 22, 2017, 10: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, 07:48:30 PM by Carmichael »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: set u gui sprite error playmaker
« Reply #1 on: June 23, 2017, 03: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
Re: set u gui sprite error playmaker
« Reply #2 on: June 23, 2017, 01:52:24 PM »
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

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: set u gui sprite error playmaker[solved]
« Reply #3 on: August 01, 2018, 01:28:24 PM »
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.

miguelfanclub

  • Full Member
  • ***
  • Posts: 165
Re: set u gui sprite error playmaker[solved]
« Reply #4 on: March 26, 2019, 06:08:20 PM »
I remember doing this before but its not working anymore.

Im seting an image via "U Gui Image Set Sprite" with an sprite var and its not working. Seting the var to Object and selecting Unity.Engine - Sprite does change the var type to sprite automatically again (i dont recall this in the past)

InvalidCastException: Cannot cast from source type to destination type.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: set u gui sprite error playmaker[solved]
« Reply #5 on: March 29, 2019, 02:19:17 AM »