Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Ofonna on June 22, 2017, 10:40:49 PM

Title: set u gui sprite error playmaker[solved]
Post by: Ofonna 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!
Title: Re: set u gui sprite error playmaker
Post by: jeanfabre 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

(http://i.imgur.com/1JecG4G.png)

is this the action you use?


Bye,

 Jean
Title: Re: set u gui sprite error playmaker
Post by: Ofonna 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)
Title: Re: set u gui sprite error playmaker[solved]
Post by: Broken Stylus 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.
Title: Re: set u gui sprite error playmaker[solved]
Post by: miguelfanclub 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.
Title: Re: set u gui sprite error playmaker[solved]
Post by: jeanfabre on March 29, 2019, 02:19:17 AM
Hi,

 please don't double post: https://hutonggames.com/playmakerforum/index.php?topic=20304.msg88999#msg88999

Bye,

 Jean