playMaker

Author Topic: ArrayMaker holding on to deleted object reference  (Read 1912 times)

cdutoit

  • Playmaker Newbie
  • *
  • Posts: 28
ArrayMaker holding on to deleted object reference
« on: September 02, 2013, 09:58:25 AM »
Hi -

Hoping someone can shed some light on this.

I have an array of objects (using Arraymaker).
eg:
arr[0] = Object1
arr[1] = Object2

Based on some event, I destroy one of the gameobjects that is in the array list.

eg. Destroy Object 1

If I immediately query my array, the object is still in the array even though it was destroyed. If I put a few seconds delay before querying it, then the array list correctly reflects that it is no longer referencing the object.

eg. Querying immediately for arr[0] returns Object1. If I wait a few seconds and query arr[0] I get none (I expected to get none).

Why would it take time for the array to "wake up" to the fact that one of its member objects has been destroyed? That is, if I immediately query the array after the destroy, it still returns the object.

Thanks for any insight.

Chris

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: ArrayMaker holding on to deleted object reference
« Reply #1 on: September 10, 2013, 06:10:44 AM »
Hi,

 that's something to be expected:

http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html

Quote
Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering.

so, you have to wait one frame to make sure destroy did it's job.

Bye,

Jean


cdutoit

  • Playmaker Newbie
  • *
  • Posts: 28
[SOLVED] Re: ArrayMaker holding on to deleted object reference
« Reply #2 on: September 16, 2013, 06:36:16 AM »
Ah, thanks!!