deleting mounted lights? how?
by deepscratch · in Torque 3D Professional · 10/02/2009 (6:24 pm) · 11 replies
hi,
so I have spotlights mounted to my vehicle as headlights,
they work fine,
but when the vehicle gets destroyed, I cant get the spotlights to delete.
any ideas?
I create them in the ::onAdd, thus,
I've tried to delete them like this:
why cant I delete these lights? the vehicle gets deleted, there is no spoon, but the lights remain.
help?
so I have spotlights mounted to my vehicle as headlights,
they work fine,
but when the vehicle gets destroyed, I cant get the spotlights to delete.
any ideas?
I create them in the ::onAdd, thus,
%headLight1 = new SpotLight() {
stuff;
stuff;
more stuff;
and more stuff still;
}
%obj.mountObject(%headlight1, 10);I've tried to delete them like this:
%obj.headlight1shape = %headlight1;
if(isObject(%obj.headlight1shape))
{
%this.unmountObject(%obj.headlight1shape);
%obj.headlight1shape.schedule(1, "delete");
}wont delete%obj.headlight1shape.schedule(1, "delete");wont delete
%headlight1.schedule(1, "delete");wont delete
why cant I delete these lights? the vehicle gets deleted, there is no spoon, but the lights remain.
help?
About the author
email me at medan121@gmail.com
Recent Threads
#3
get a error on closing the level with this change,
dont know why.
maybe the spotlights are not being released?
10/02/2009 (8:59 pm)
mm,get a error on closing the level with this change,
dont know why.
maybe the spotlights are not being released?
#4
10/03/2009 (2:40 am)
Well, another idea is to add an option to LightBase like "ownedByMount" which you could set true on your field, then do something like this ( in C++ )void LightBase::onDeleteNotify(SimObject* obj)
{
Parent::onDeleteNotify(obj);
if (obj == mMount.object)
{
unmount();
// Added this:
if ( mOwnedByMount )
deleteObject();
}
}
#5
the error on exiting the mission occurs if there is a vehicle with a spotlight attached to it, and the vehicle is unharmed, ie; it still has its light.
if I destroy the vehicle, then exit, there is no error on exit.
something in the way the lights are added to the vehicle maybe??
10/03/2009 (7:52 am)
ok,the error on exiting the mission occurs if there is a vehicle with a spotlight attached to it, and the vehicle is unharmed, ie; it still has its light.
if I destroy the vehicle, then exit, there is no error on exit.
something in the way the lights are added to the vehicle maybe??
#6
10/03/2009 (10:34 am)
Can't you just turn the lights off on exit? Have them all load into a simgroup or something, then affect the simgroup on quit?
#7
but it has no effect on the error, which occurs if the vehicle is not destroyed, thus the light is still mounted.
@ Steve,
how would you go about switching the lights off?,
sounds like a good idea
10/03/2009 (10:34 am)
I implemented the bool,but it has no effect on the error, which occurs if the vehicle is not destroyed, thus the light is still mounted.
@ Steve,
how would you go about switching the lights off?,
sounds like a good idea
#8
10/03/2009 (11:01 am)
Load them all up into a simgroup on creation, then turn off everything in the simgroup on mission exit/disconnect server/whatever teh function is. Or alternatively delete them all, or blow up your cars or something ... something that works.echo("Simgroup vehiclelightsgroup - Lights off ");
for(%i=0; %i < vehiclelightsgroup.getCount(); %i++)
{
%obj = vehiclelightsgroup.getObject(%i);
%obj.setlightenabled(0);
}
#9
Or maybe it could be as simple as adding the light to the MissionCleanup SimGroup when it's added/created.
10/03/2009 (4:17 pm)
Hmm, it didn't actually occur to me until later but in TGE/TGEa there was an "attachToObject" console method that was used to attach lights to things. It had a counter method "detachFromObject" that took care of deleting and cleaning up the light/object instances.Or maybe it could be as simple as adding the light to the MissionCleanup SimGroup when it's added/created.
#10
I'll look at "detachFromObject" and see what I can find out.
its strange, the error happens instantly when I click yes to exit the mission, like really instantly, something is dodgy,
maybe lights weren't meant to be mounted and I found a loophole??
dunno, but I realy need to find a fix for this.
Steves idea did not work eather, but, yes, if there is a way to delete all the vehicles on exit, that should work, but the error happens way to fast...
10/03/2009 (4:40 pm)
ok, missioncleanup did not work,I'll look at "detachFromObject" and see what I can find out.
its strange, the error happens instantly when I click yes to exit the mission, like really instantly, something is dodgy,
maybe lights weren't meant to be mounted and I found a loophole??
dunno, but I realy need to find a fix for this.
Steves idea did not work eather, but, yes, if there is a way to delete all the vehicles on exit, that should work, but the error happens way to fast...
#11
Also, and rather hackily, if it errs so fast on exit, perhaps fix the GUI to first sort out the problems and then schedule a seperate function for the exit.
10/03/2009 (7:51 pm)
What actually is the error? Console error?Also, and rather hackily, if it errs so fast on exit, perhaps fix the GUI to first sort out the problems and then schedule a seperate function for the exit.
Associate Michael Hall
Distracted...
// inside your onAdd() or onMount or onWhatever function %headLight1 = new SpotLight() { stuff; stuff; more stuff; and more stuff still; } // I'm assuming %obj for you is the vehicle object %obj.mountObject(%headlight1, 10); %obj.light = %headLight1And then try deleting it like this:function VehicleData::onRemove(%this, %obj) { // stuff if(isObject(%obj.light)) %obj.light.delete(); }Don't know if it would work or not -- I'm not at my computer, but that's how my 1st attempt at it would look.
I'm thinking that where you're going wrong is when you try to sayIt's possible that %obj is already invalid or null by the time you get here, so it doesn't know who or what %obj is. Throw an echo in there to find out.