Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Right. Im running into some weird issue with android unity. I have this bit of code

function OnTriggerStay (other : Collider)
{

        if(die.GetComponent(DieScript).sideUp ==6 ||die.GetComponent(DieScript).sideUp ==2 || die.GetComponent(DieScript).sideUp ==4)
    {

       parSys.startSpeed = -5;
        if (other.attachedRigidbody)
        {
        var direction = -(other.attachedRigidbody.transform.position - transform.position*1.5);
            other.attachedRigidbody.AddForce(direction);
        }

        }

Now, this runs fine in the unity editor. More then fine, It runs perfectly. However on android the whole OnTriggerStay method fails, and I get this error from logcat

I/Unity   (29199): NullReferenceException: Object reference not set to an instance of an object

I/Unity   (29199):   at ZoneScriptDie.OnTriggerStay (UnityEngine.Collider other) [0x00000] in <filename unknown>:0 

I/Unity   (29199):  

I/Unity   (29199): (Filename:  Line: -1)

I/Unity   (29199): 

I/Unity   (29199): NullReferenceException: Object reference not set to an instance of an object

I/Unity   (29199):   at ZoneScriptDie.OnTriggerStay (UnityEngine.Collider other) [0x00000] in <filename unknown>:0 

I/Unity   (29199):  

Why is it failing in android? The whole object freezes up, the particles just hang in place like a frozen snowglobe.

share|improve this question
    
If you put a lot of debug output in there, you could narrow down the precise line the null reference is occurring on. If I had to guess, it's possible that die may be the object that doesn't have a reference. –  chaosTechnician Dec 29 '12 at 6:16
    
Unfortunatly. Thats really all the debug out put I got from Logcat, Its just repeats a bunch of times. link And in start I have parSys = GetComponent(ParticleSystem); die = GameObject.Find("die"); So It should exist. It exists and runs fine in the editor, but not on android. Ill try playing with how it finds the object –  ProtoJazz Dec 29 '12 at 6:35
    
Maybe There would be a better way to log the date? Or would all the non unity debug help? –  ProtoJazz Dec 29 '12 at 6:41

1 Answer 1

up vote 0 down vote accepted

I think I fixed it, I changed the code from

die = GameObject.find("die"); //Worked fine in the editor to die = gameObject.transform.parent.gameObject;

It now runs fine on the phone. So Yes chaosTechnician was right, It wasnt being set. That being said does anyone know why it is that That particular gameObject.find didnt work?

share|improve this answer
    
That's not something we can answer without knowing about that object or how your system manipulates it. Perhaps you were making assumptions about how late it would be destroyed which don't hold true on all platforms. –  Kylotan Dec 29 '12 at 10:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.