playMaker

Author Topic: Help with Casting FsmObject to specific type.  (Read 2020 times)

Jos Yule

  • Playmaker Newbie
  • *
  • Posts: 33
    • View Profile
Help with Casting FsmObject to specific type.
« on: May 30, 2012, 09:59:25 AM »
Hello.

I'm working on an ex2D action - "Set Sprite". The action will allow you to dynamically set the sprite of a Game Object which has an exSprite attached.

I've used the ExSpriteAnimationPlay action code as a base.

My problem is that you need to denote the exAtlas from which the sprite should be taken. This atlas lives in the Project Hierarchy. I've got a var setup to hold this reference:

Code: [Select]
[RequiredField]
[Tooltip("The Sprite Atlas to pull the new sprite from.")]
public FsmObject spriteAtlas;

I originally had the spriteAtlas var set as an exAtlas type:

Code: [Select]
public exAtlas spriteAtlas;
But then i couldn't drag/drop the actual atlas from the Project tab into this slot.

So, i'm now trying to figure out how to cast from FsmObject to the specific exAtlas type. This is what i'm doing now, which isn't working:

Code: [Select]
var realAtlas = (exAtlas)spriteAtlas.Value;
Any suggestions? Would love to know how to deal with non-fsm specific var's in Actions.

Thanks!
Jos

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15082
  • Official Playmaker Support
    • View Profile
Re: Help with Casting FsmObject to specific type.
« Reply #1 on: May 30, 2012, 11:03:18 AM »
Hi,

 Yes, it's always a problem to reference non component classes. I can't really tell you any solution as is since I haven't yet tested ex2d. I am unavailable until next week, but I will give it a try and see what kind of solution can be created to solve your issue. Meanwhile if you find a way, even better :)

 bye,

 Jean

Jos Yule

  • Playmaker Newbie
  • *
  • Posts: 33
    • View Profile
Re: Help with Casting FsmObject to specific type.
« Reply #2 on: May 30, 2012, 11:50:57 AM »
Well, I solved it in a round-about kind of way.

Code: [Select]
exAtlas realAtlas = Resources.Load(atlasName.Value, typeof(exAtlas)) as exAtlas;

I've changed the required params to now be the Object with the exSprite, the sprite name and the atlas name. I then load the atlas via the Resources.Load() method.

This works for me, but i'm not sure of the cost (memory/cpu) of using the Resources.Load() method. I'm making an assumption (bad idea, i know) that the exAtlas is already loaded, as you are using it in your project, so this shouldn't use any more memory. But it is something that really needs to be tested.

Regardless, it would be great to have a way to add new variable types to PlayMaker.

I've posted it here.

Jos