Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JMAA · Jan 11, 2013 at 12:26 PM · androidraycastcrashfreeze

Raycasting freezes the Android device?

Hello, guys, I was having issues with this bit of code:

     var ray;
     var hit : RaycastHit;
     var obj : infoLibro;
     var vektor : Vector3;
     if(Input.touches.Length > 0) {
         vektor = Vector3(Input.GetTouch(0).position.x,Input.GetTouch(0).position.y,0f);
         ray = Camera.main.ScreenPointToRay (vektor);
         if(Physics.Raycast(ray, hit, 100)) {
             if(hit.transform.gameObject.tag == "libro") {
                 nameObj = hit.collider.gameObject.name;
                 hRay = true;
                 obj = hit.transform.gameObject.GetComponent("infoLibro");
                 obj.HoverIn();
                 
             }
         } else {
             obj.HoverOut();
             hRay = false;
             nameObj = "";
         }
         if(Input.GetTouch(0).tapCount == 2 && Physics.Raycast(ray, hit, 100)) if(hit.transform.gameObject.tag == "libro") obj.Click();
     } else {
         obj.HoverOut();
     }

This script calls other functions belonging to components in the gameObject it's calling (HoverIn(), HoverOut() and Click()). It runs OK in PC using Remote, but when I do this in the very Android device the game freezes and crashes itself.

I imagined like there was a problem with the performance pertaining to Physics.Raycast(), but I also take in mind that the object type this snippet is calling (those with the "libro" tag) are around 3000 in total. They all have the same script in them (infoLibro).

I'm also including the code for those functions it's calling:

 function HoverIn () {
     
     shaderAnterior = renderer.material.shader;
     if(esHueco) colorAnterior = Color.white;
     ratonEncima = true;
     //renderer.material.shader = Shader.Find("Unlit/Texture");
     scriptInput.objetivo = gameObject;
     scriptInput.objActivo = true;
     
     if(scriptInput.estanteria) {
         
         if(esHueco) {
             renderer.material.color = Color.blue;
             scriptEst.hueco = gameObject;
         }
     }
 }
 
 function HoverOut () {
     
     ratonEncima = false;
     /*
     if(!esHueco) renderer.material.shader = shaderAnterior;
     else {
         renderer.material.shader = shaderAnterior;
         renderer.material.color = colorAnterior;
     }*/
     activaEncima = false;
     scriptInput.objetivo = null;
     scriptInput.objActivo = false;
 }
 
 function Click () {
     scriptWatcher = GameObject.Find("watcher").GetComponent(librosWatcher);
     scriptPila = GameObject.Find("zonaPila").GetComponent(scriptZonaPila);
     shaderAnterior = renderer.material.shader;
     if(esHueco) colorAnterior = Color.white;
     ratonEncima = true;
     //renderer.material.shader = Shader.Find("Unlit/Texture");
     scriptInput.objetivo = gameObject;
     scriptInput.objActivo = true;
     
     if(scriptInput.estanteria) {
         
         if(esHueco) {
             renderer.material.color = Color.blue;
             scriptEst.hueco = gameObject;
         }
     }
     
     var camaraActiva : GameObject;
     camaraActiva = GameObject.Find("renderTexCam");
     //if(Input.GetButton("Fire1") && ratonEncima && esPila && scriptPila.dentro1) {
     if(esPila) {
             //scriptWatcher.DestruirLibro(scriptWatcher.idLibroActual);
             scriptWatcher.librosEstado[scriptWatcher.idLibroActual] = 1;
             scriptZonaPila.libroEnMano = scriptWatcher.libro[scriptWatcher.idLibroActual];
             scriptZonaPila.libroEnMano.Destroy(rigidbody);
             scriptZonaPila.libroEnMano.transform.position = GameObject.Find("Bone04").transform.position;
             scriptZonaPila.libroEnMano.transform.rotation = GameObject.Find("Bone04").transform.rotation;
             scriptZonaPila.libroEnMano.transform.parent = GameObject.Find("Bone04").transform;
             var pipi : infoLibro = scriptZonaPila.libroEnMano.GetComponent(infoLibro);
             scriptZonaPila.libroEnMano.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");
             //scriptZonaPila.libroEnMano.collider.enabled = false;
             //libroScript = libroEnMano.GetComponent("infoLibro");
     }
     
     if(esHueco) {
         scriptEst = GameObject.Find(receptorEs).GetComponent(triggerEstanteria); //hAhahHAhaHAaAhaAHhaAahAHaHAhhAHahHAhaHAaHAHahAhaAhaHAahAhaHAAHahAHahAHhah
         activaEncima = true;
     }
     
     if(esHueco) {
         //print("Ahmed");
         if(activaEncima) scriptEst.ComprobarLibro();
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by PAEvenson · Jan 11, 2013 at 02:54 PM

You have some major issues with you implementation. First, the reason it runs fine on PC is because nothing under the if(Input.touches.Length > 0) will be called. Unless you have a touch monitor. The only place you set obj is here:

 obj = hit.transform.gameObject.GetComponent("infoLibro");

so all of your obj.HoverOut(); calls will be throwing a nullReference Exception. If you are doing this 3000 times a frame that could be the issue.

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PAEvenson · Jan 11, 2013 at 02:56 PM 0
Share

I suggest getting it working with Input.Get$$anonymous$$ouseDown(0) before you switch it to handle touches

avatar image JMAA · Jan 14, 2013 at 01:53 PM 0
Share

A little update: the first snippet of code runs on a single user object, not on the 3000 objects there. The thing is that now that I've modified the script accordingly, it works, but takes too much consumption of Overhead and Script CPU use in the device it slows it down to 15FPS.

avatar image PAEvenson · Jan 14, 2013 at 05:09 PM 0
Share

It shouldnt...The issue is somewhere else. I have a game that does a couple hundred every frame with little to no frame rate difference. Check your log file.

avatar image JMAA · Jan 16, 2013 at 12:12 PM 0
Share

A little more details on the issue right now:

The thing is that the 3000 books' (or gameObjects) are overloading the device's CPU with their Update() function. The problem is that now they still consume CPU having in Update() no script contents (just around 4 uncommented lines of code), and aside of the Overhead lag is a problem.

I don't know BTW why the Unity log isn't telling me anything from debugging the compiled debug app in the device except while it's compiling. I have the Development Build option turned on along with all those Build & Run settings, but all it tells while compiling the build is warnings about shaders (which have nothing to see with the scene I'm having this problem, they're on other scenes perhaps).

avatar image robertbu · Jan 16, 2013 at 01:31 PM 0
Share

If the 3000 books have visual representation, it is far more likely that displaying the books is slowing things down than 3000 empty Update() calls. To test, turn off the renderer for the books and see what happens...or if you have Pro, run the profiler.

Show more comments
avatar image
0

Answer by JMAA · Jan 18, 2013 at 12:51 PM

So I realized something was wrong: the raycast script needed to be on the user GameObject, not on the books.

But still, I get the crash on the device, maybe because of the rendering lag included in the CPU consumption. I tried changing the Occlusion mode to PVS, but I still get a lot of Overhead lag.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity AdMob Crashes After VideoAd Load (Android) 0 Answers

Unity crashes when using while 2 Answers

Android 9 - Graphical freeze but scene runs in the background 0 Answers

What might cause an Android app to freeze 1 Answer

[SOLVED] Android Lags Then Crashes When Looking Around 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges