Creating an NRaas project Difference between Destroy and Dispose?

Talk nerdy to us here.
Post Reply
icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Difference between Destroy and Dispose?

Post by icarus_allsorts » March 25th, 2016, 11:07 am

Specifically when it comes to a GameObject, it seems that in most cases where you'd want to get rid of an object Destroy is the go to method, but there does also seem to be some important-ish looking code in DIspose that would seem odd if it was never run on the object being destroyed. I guess my main question would be does Dispose() perhaps get used somewhere along the line after Destroy() runs?

User avatar
Chain_Reaction
Site Admin
Reactions:
Posts: 7568
Joined: December 30th, 2011, 6:00 pm
Answers: 81
Contact:

Post by Chain_Reaction » March 25th, 2016, 5:04 pm

Destroy seems to only be useful when you want to remove the object from the world/simulator but not actually kill it's data structure (such has destroying a Sim object during hibernation). Dispose is when you want it to die. Generally I do both when getting rid of things. It appears EA is a big fan of destroy which is why ET is needed to actually get rid of the data using dispose.

User avatar
igazor
Organizer
Reactions:
Posts: 17102
Joined: April 8th, 2013, 6:00 pm
Answers: 203
Location: Everyone should strive to find their inner platypus.

Post by igazor » March 25th, 2016, 5:18 pm

Without meaning to, and without even asking a non-coder to participate over here, you guys have just solved a weird mystery for me that I had been saving to present some day. I have a screenshot taken in Edit Town at the precise moment an NPC babysitter left the lot where he was working, was on his way who knows where (home, off the map I suppose), and Tagger was reporting his current action as "Destroy Myself."

Am pretty sure players weren't really supposed to ever see that, but at least now I know what it meant, and it wasn't nearly as sad as I thought! :)

User avatar
Chain_Reaction
Site Admin
Reactions:
Posts: 7568
Joined: December 30th, 2011, 6:00 pm
Answers: 81
Contact:

Post by Chain_Reaction » March 25th, 2016, 5:31 pm

Yes, service Sims run that interaction when they are going into hibernation. You wouldn't ever normally see what interaction they are running because it's not possible to make them selectable.

icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Post by icarus_allsorts » March 25th, 2016, 5:47 pm

Ah, so for an object that has no business being around in the game anymore I should run both Destroy and Dispose then, presumably in that order?

User avatar
Chain_Reaction
Site Admin
Reactions:
Posts: 7568
Joined: December 30th, 2011, 6:00 pm
Answers: 81
Contact:

Post by Chain_Reaction » March 27th, 2016, 4:20 pm

Sounds good :)

icarus_allsorts
Reactions:
Posts: 213
Joined: March 8th, 2012, 6:00 pm

Post by icarus_allsorts » March 28th, 2016, 12:54 am

Thanks :)

Post Reply