playMaker

Author Topic: Feels like I've made this more complicated than necessary...  (Read 1607 times)

eros

  • Playmaker Newbie
  • *
  • Posts: 9
Feels like I've made this more complicated than necessary...
« on: December 27, 2021, 06:32:41 PM »
Hi all! Just recently got into Unity and picked up playMaker to learn them both concurrently. Very impressed with the power and versatility so far, but I've been hammering away at something for the past couple of days and hoping someone can tell me the best way to go about this:

I'm trying to make a simple email/inbox that I can populate with buttons and strings from an array list. My plan was to use a UGUI scroll rect with vertical layout group and content fitter, and just spawn instances of a button prefab into that, with the buttons themselves representing email links. My button prefab FSM tags each instance at runtime based on string data passed from the main FSM. I then tuck those instances into a GO array list so they can be recalled on demand by tag.

The next part of my (what I'm beginning to feel was a very bad) plan was to just destroy each button GO onclick (after displaying referenced text from the array list in a popop) and then create it again from the array list so that the "new" button automagically spawns into the vertical layout group at the bottom of the list. Everything works beautifully except for that last bit.

I didn't account for the fact that prefab instances are ALWAYS treated as prefabs regardless of whatever tomfoolery I employ to uniquely ID them at runtime lol. Whoops.

I know there is a more elegant way to go about this, and I'm pretty sure I'm either on the verge of making this work, or I'm going to have to try a different approach entirely. It's been a valuable learning experience either way.

Noob welcomes any input and/or suggestions!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Feels like I've made this more complicated than necessary...
« Reply #1 on: December 27, 2021, 11:16:11 PM »
Hi.
For reusing prefabs you should look into pooling them.

On Spawning(creating) you can use Set Fsm actions to set some data to it (for example a int for index or a string for a reference to display the mail)

You can send a event to it when the data is set and the prefab can handle to set (for example, a subject text next to the mail image)

or what i also do sometimes when using for example a ID nr.
of the Prefab set the default ID value to -1
also make a state with a global "DISABLE" transition (system event)
in that state do a Set Int Value for the ID to set back to -1

in the start state have a int compare set to every frame and if Equal or greater than 0 transition to the next state.

eros

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Feels like I've made this more complicated than necessary...
« Reply #2 on: February 04, 2022, 01:00:00 AM »
I was indeed making it way more complicated than it should've been. Ended up just shoving everything into hash tables and working from there.

I did learn a great deal about pooling with PM while researching your suggestion, djaydino, so thanks for that!