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
  Adjust radius of generated mesh via script? Shackman 1 4 03-26-2024, 01:12 PM
Last Post: _Aka_
  Removing the objects behind an object alms94 6 6 12-06-2023, 09:31 PM
Last Post: _Aka_
  Get spline from generated mesh beartrox 1 5 11-27-2023, 12:30 PM
Last Post: _Aka_
  Making "gaps" in the generated spline mesh VoltDriver 6 24 11-22-2023, 11:34 PM
Last Post: _Aka_

Forum Jump: