Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Budde88 on December 20, 2016, 07:43:26 AM

Title: Find FSM variables of the SAME instantiated prefab.
Post by: Budde88 on December 20, 2016, 07:43:26 AM
So I need to find the variable of an instantiated prefab, and that's fine I know how to do it, but my problem is more specific.

How do I find the variable of an instantiated prefab if I have spawned mutliple versions of the same prefab.

For example I have one prefab with a FSM that holds numerous variables.

Booster (Prefab)
- FSM string variable
- FSM int variable
- etc...


I can access these variables by storing their values right, but when I spawn mutliple versions with new values each time, I can only access the last instantiated prefabs variables because the values are updated every time a new one is spawned.

Attachment added for more clarity
Title: Re: Find FSM variables of the SAME instantiated prefab.
Post by: Budde88 on December 20, 2016, 08:33:09 AM
Alternatively,

If someone could suggest a workaround of how I could get a Prefab to reference a gameobject in the scene, I'd be quite content with that.

Thanks
Title: Re: Find FSM variables of the SAME instantiated prefab.
Post by: djaydino on December 21, 2016, 02:36:08 AM
Hi,
you can use arrays for this.

there are some array tutorials here (https://hutonggames.fogbugz.com/default.asp?W548)
Title: Re: Find FSM variables of the SAME instantiated prefab.
Post by: Budde88 on December 21, 2016, 05:57:43 AM
Hey,

I should probably explain my problem a little more.

I know I can store the gameobjects in an array, the problem is
I spawn the prefabs into a scrollview, and when the specific prefabs are centered
in the scrollview I need to get the values inside the centered prefab, but I don't know what index they are in the Array.

Any suggestions?
Title: Re: Find FSM variables of the SAME instantiated prefab.
Post by: djaydino on December 21, 2016, 08:53:01 AM
Hi.
When you create a prefab you need to add it to an array and also the variables you need place into different arrays.

Then use the action "Array Contains" to find the prefab and store the index number.
Then you can use that index number to get the variables on the other arrays.
Title: Re: Find FSM variables of the SAME instantiated prefab.
Post by: Budde88 on December 21, 2016, 09:03:07 AM
Thanks,

Will give it a go now :)

Hold thumbs!
Title: Re: Find FSM variables of the SAME instantiated prefab.
Post by: djaydino on December 21, 2016, 10:41:42 AM
Hi, yes it can.
You need add each spawned object to the array
Title: Re: Find FSM variables of the SAME instantiated prefab.
Post by: Budde88 on December 21, 2016, 10:46:38 AM
When I use the 'Array contains' action, I have to reference either the Prefab itself OR I store the Prefab into a Gameobject variable and reference that.

If I store it into a Gameobject variable and reference it, I will always find the last index of the array because every time I spawn a new prefab, it updates the Gameobject variable.

If I reference the Prefab itself, It will only find the variables of the prefab that never actually spawned into the scene.

I am not sure if I'm doing what you suggested the wrong way, but I did try and it doesn't seem to be working.


Maybe someone can offer some advice as to what I may be doing wrong. I will post images if you need clarity.

Thanks
Title: Re: Find FSM variables of the SAME instantiated prefab.
Post by: djaydino on December 21, 2016, 11:03:29 AM
I am not sure what you are trying to achieve

But you will need to select one of the instantiated prefabs and place that into a variable.
Then you can get the index number from that instantiated prefab

There are different ways to select the prefab (triggers / mouseover / and so on)
but that depend on your project.
Title: Re: Find FSM variables of the SAME instantiated prefab.
Post by: Budde88 on December 21, 2016, 11:48:46 AM
Hey,

Thanks for the help I really do appreciate it.
I couldn't get it to work, but it's fine :)

I did manage to find a workaround to my issue that
believe it or not was something I tried before but
just didn't work.

Thanks again, I really appreciate that you took
the time to help me out.