Posts: 7
Threads: 2
Joined: Apr 2017
Hello Curvy folks!
I hope there's a simple solution for what I need to do:
I have a generator that creates game objects along the spline (imagine sleepers on a train track). As these objects are created, they add themselves to an array. So far so good.
However, if I delete a Control Point, I need a way to send an event to the sleepers that are being removed, so that they can remove themselves from the array before destroying themselves.
I appreciate any advice!
Posts: 2,118
Threads: 93
Joined: Jun 2017
Hi
You can either listen to the OnRefresh event of either the spline, the generator, or a module of the generator. Modules also have an OnBeforeRefresh event.
In the event listener, you can update your array.
Did this help?
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 7
Threads: 2
Joined: Apr 2017
Thank you for the reply!
It helps a bit - I am actually sending an event on Refresh to a Playmaker FSM.
But, I need to send an event specifically to all the created Game Objects (sleepers) that are being removed when the ControlPoint is deleted, before the sleepers are actually deleted. I'm not sure how to go about this.
Posts: 2,118
Threads: 93
Joined: Jun 2017
It is a bit complicated:
I am assuming that you are using the Create GameObject module to create the sleepers. In that case, your module uses in play mode a pool to reuse instances of your sleepers, for performance reasons. The deleted sleepers are pushed, again in play mode, to the pool. Before pushing them, it calls the IPoolable.OnBeforePush if any. So add to your sleepers a script that implements the IPoolable interface, and put your behaviour in the OnBeforePush method.
Did this help?
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 2,118
Threads: 93
Joined: Jun 2017
But if your goal is to only update the array you have, just make it reflects the list of the children of the Create GameObject module, no need for events I believe. You can also use the CreateGameObject.GameObjects.Items property, which is a list of the game objects currently created by the module
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 7
Threads: 2
Joined: Apr 2017
12-03-2021, 12:24 AM
(This post was last modified: 12-03-2021, 12:24 AM by toxicfrog.)
That does help, but it's beyond my abilities to write such a script.
However, your replies led me to a new solution that seems to be working as intended!
I'm filling the array with children of the Generator object that spawns the sleepers. So, now my array is always in sync with the active sleepers in the scene. Problem solved!
I appreciate your help!
Posts: 2,118
Threads: 93
Joined: Jun 2017
You are welcome.
If and when you feel like it, please leave a review for the asset, that helps a lot.
Have a nice day
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 7
Threads: 2
Joined: Apr 2017
Posts: 2,118
Threads: 93
Joined: Jun 2017
Thanks
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.