playMaker

Author Topic: Create object from ArrayMaker List results in error [SOLVED]  (Read 2939 times)

10high

  • Playmaker Newbie
  • *
  • Posts: 33
    • Cult Manager - Google Play
Create object from ArrayMaker List results in error [SOLVED]
« on: March 02, 2018, 07:49:41 AM »
Hi, I haven't found a previous post about this, so I hope this hasn't already been asked:

I have an ArrayMaker proxy list attached to a prefab that is in the scene. I add prefabs to this ArrayMaker List to create a kind of pool to draw from.
 
I then use "ArrayList Get" and store the result in a game object variable.

I then use "create object" to spawn the game object stored in that variable.

It seems to work as intended. The game object spawns and is fully functional, but I get the error message "InvalidCastException: Cannot cast from source type to destination type".

Everything works as it should, except for the error appearing.

Is my method bad practice? Or is the error message a bug?

Thanks in advance.
« Last Edit: March 04, 2018, 06:42:46 PM by djaydino »
Cult Manager


RAVEN001

  • Junior Playmaker
  • **
  • Posts: 66
  • BANNED
Re: Create object from ArrayMaker List results in error
« Reply #1 on: March 02, 2018, 09:00:13 AM »
you have a raycast event somewhere, where the ray cant cast to its selected object. if your fsm is functioning fine, you may have a double reference to the action your trying to activate.
BANNED

RAVEN001

  • Junior Playmaker
  • **
  • Posts: 66
  • BANNED
Re: Create object from ArrayMaker List results in error
« Reply #2 on: March 02, 2018, 09:05:29 AM »
the other thing is, if youre referencing other prefabs they may only referene other prefabs or global variables.
BANNED

10high

  • Playmaker Newbie
  • *
  • Posts: 33
    • Cult Manager - Google Play
Re: Create object from ArrayMaker List results in error
« Reply #3 on: March 02, 2018, 09:25:02 AM »
Thanks, but that's not it. I have traced the error to when I use "create object" to spawn a game object stored in a variable pulled from an ArrayMaker List.

I do have a raycast in the scene, but when I disable the FSM, the error still appears.

And it's not a referencing problem. Like I said, the game object spawns fine, everything works fine, but I get this annoying error message. 
Cult Manager


RAVEN001

  • Junior Playmaker
  • **
  • Posts: 66
  • BANNED
Re: Create object from ArrayMaker List results in error
« Reply #4 on: March 02, 2018, 10:09:43 AM »
is that an object 'in scene' or is it another prefab? if it is in scene you need to instantiate it. so the 'START' event should be set object, game object>global object, then all your prefabs can access it via the instantiated global variable, then an array or other reference should find it.
BANNED

10high

  • Playmaker Newbie
  • *
  • Posts: 33
    • Cult Manager - Google Play
Re: Create object from ArrayMaker List results in error
« Reply #5 on: March 04, 2018, 07:25:10 AM »
Thanks and sorry for not being clear. I can instantiate game objects no problem.

However, when I instantiate a game object from an ArrayMaker List, it instantiates the object (yay!) but also returns the error message quoted above (boo).

I was therefore wondering if instantiating a game object from an ArrayMaker List is bad practice or if the error message is a bug?

Clarification on this would be much appreciated. At the moment I'm simply ignoring the error messages, but it would be good to know if I should be doing it a different way.
Cult Manager


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Create object from ArrayMaker List results in error
« Reply #6 on: March 04, 2018, 08:51:15 AM »
Hi,
Are there some fsm/actions on the created object.
I think a different action is giving this error.

anyway, creating and destroying is actually a bad practice except if you need to use the object only once or twice.

else you should pool your objects.

You can check this post, it has some nice actions for pooling :
http://hutonggames.com/playmakerforum/index.php?topic=12941.0

10high

  • Playmaker Newbie
  • *
  • Posts: 33
    • Cult Manager - Google Play
Re: Create object from ArrayMaker List results in error
« Reply #7 on: March 04, 2018, 09:15:31 AM »
Hahahaha (this is the sound of me laughing insanely)

Yes - I stumbled on the cause by chance: The instantiated game objects have an FSM with a "run FSM" action. That template includes a "find closest" action.

It didn't occur to me because the template doesn't run on start. But even though it wasn't being called to run, it was still causing this error message. When I created the template the game objects had rigid bodies, but then I later removed them for a different reason and because the template is called infrequently I didn't notice that problem etc. etc.

Thank you guys - sorry RAVEN001 that I dismissed the initial raycast solution.

And thanks for the pooling suggestion, it's something I need to think/learn about.   
Cult Manager