x


missing (transform) vs none: how to code this or query for it?

Hi,

In the inspector, the drop down field used to reference transform or game object knows the difference between "none" and "missing",

that is if I delete a reference that was hooked to a public var in a script, the inspector fields shows "missing (transform)". This is very good, but I need to catch this now within my code to act upon this. I have scripted something that works, but it's really, really hacky and involves scanning all transforms... not very nice, hopefully there is a better way.

I wonder how this is coded and if the api ( editor or general) expose a function or flag for this, I failed to find anything on that matter in the help.

Thanks for your help,

Bye,

Jean

more ▼

asked Nov 22 '10 at 06:09 AM

Jean Fabre gravatar image

Jean Fabre
3.1k 68 75 103

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Probably a memory thing. A reference marked as "null" would cause a none, while a reference to an object that's either marked for garbage-collection, or been garbage-collected, or something to that effect, would cause a missing.

The question is, do you really care about the difference or do you just want to know when your object has, for example, lots its target, and take action? If it's the former then I'm afraid I'm of no help. If it's the latter, then there are at least two ways to handle it. The easy way is to check either periodically, or on access, whether the object is there or not. The smart way is to code events using C# that your script can subscribe to, such as, say "OnLostTarget", that you can then take action on (in this case, trying to reacquire a target). The MSDN has info on how to set up a basic event system. This could also be accomplished in a simplified form using Unity's SendMessage function, but that's got a few disadvantages compared to events.

more ▼

answered Nov 23 '10 at 10:27 PM

TheDemiurge gravatar image

TheDemiurge
571 2 3 14

I do care about the difference indeed, I will look at that onlosttarget thing, and see how it goes. thanks.

Nov 25 '10 at 06:09 AM Jean Fabre
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x467
x348
x263
x131
x8

asked: Nov 22 '10 at 06:09 AM

Seen: 875 times

Last Updated: Nov 22 '10 at 06:09 AM