Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send event to generated game object upon ControlPoint deletion?
#1
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!
Reply
#2
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
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.
Reply
#4
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
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!
Reply
#7
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
DONE!
Reply
#9
Thanks Smile
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Runtime error when using Curvy Generator with Game Object Deform studentloan 3 13 04-22-2022, 09:00 PM
Last Post: _Aka_
  Can generated mesh be enabled to read/write? scr33ner 2 7 04-07-2022, 01:13 PM
Last Post: _Aka_
  Can I extract prefabs from Curvy's generated meshes? niuage 7 17 03-15-2022, 11:44 AM
Last Post: _Aka_
  Is curvyspline a good solution for a 2D rail grinding game? bazz_boyy1 2 6 03-01-2022, 11:49 AM
Last Post: _Aka_

Forum Jump: