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 Abacab · Apr 13, 2015 at 04:36 PM · c#ioscrashrenderer

EDITED rend.material change too hard to handle for iOS

EDIT: The game doesn't crash when I disable this script for all cars, which means that this script is the problem.

Hello!

I am having trouble with changing my car's color. Could this be too hard for iOS to handle?

 void Awake ()
         {    
                 if (PlayerPrefs.GetInt ("Selected Car") == 1) {
                         if (PlayerPrefs.GetInt ("Selected Colour 11") == 1) {
                                 rend.material = Car01materials [0];
                         }
                         if (PlayerPrefs.GetInt ("Selected Colour 11") == 2) {
                                 rend.material = Car01materials [1];
                         }
                         if (PlayerPrefs.GetInt ("Selected Colour 11") == 3) {
                                 rend.material = Car01materials [2];
                         }
                         if (PlayerPrefs.GetInt ("Selected Colour 11") == 4) {
                                 rend.material = Car01materials [3];
                         }
                         if (PlayerPrefs.GetInt ("Selected Colour 11") == 5) {
                                 rend.material = Car01materials [4];
                         }
                         if (PlayerPrefs.GetInt ("Selected Colour 11") == 6) {
                                 rend.material = Car01materials [5];
                         }
                 }
         }

The game crashes when I load level 1 on my iPhone. Works fine in Unity.

Comment
Add comment · Show 5
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 HarshadK · Apr 14, 2015 at 11:17 AM 0
Share

What does your log say?

Also you can optimize above code with a switch().

 void Awake ()
  {    
      if (PlayerPrefs.GetInt ("Selected Car") == 1) {
         switch(PlayerPrefs.GetInt ("Selected Colour 11"))
         {
             case 1:
                 rend.material = Car01materials [0];
                 break;
             case 2:
                 rend.material = Car01materials [1];
                 break;
             case 3:
                 rend.material = Car01materials [2];
                 break;
             case 4:
                 rend.material = Car01materials [3];
                 break;
             case 5:
                 rend.material = Car01materials [4];
                 break;
             case 6:
                 rend.material = Car01materials [6];
                 break;
                         default:
                                 // Load first material as default
                                 rend.material = Car01materials [0];
                                 break;
         }
      }
  }

Also if you are following the pattern found in your code above. You can do it in one line also as:

 void Awake ()
  {    
      if (PlayerPrefs.GetInt ("Selected Car") == 1) {
         rend.material = Car01materials [PlayerPrefs.GetInt ("Selected Colour 11") - 1];
      }
  }

But the second method is not much of stable one.

avatar image Abacab · Apr 14, 2015 at 11:26 AM 0
Share

Thanks for your comment! Previously I tried to make the colour thing work with .SetActive.

I added six different car bodies to six different cars and the game crashed when I loaded level 1. Now I only have one car body on each car, but something makes the game crash.

The game doesn't crash if I only have one colour per car.

How does the the switch case change my script performance wise?

avatar image hexagonius · Apr 14, 2015 at 12:56 PM 0
Share

Don't know about performance, but I think it's not even worth thinking about it. For your problem. I don't think the crash happens because of this script. I'd also not assign a whole new material but change it's color property. With these, you could have color pickers in the inspector, would make things more easy (if it's just a tint you're using of course).

Have you tried compiling both 32 and 64 bits? What does XCode console say at that point?

avatar image HarshadK · Apr 14, 2015 at 01:00 PM 0
Share

@Abacab

How does the the switch case change my script performance wise?

switch vs if else performance c#

But the case here is that it might not be the if else ladder that might be the cause. And that is why I asked you for the log. I think you should post your log here for perusal.

avatar image Abacab · Apr 14, 2015 at 01:05 PM 0
Share

@Harshad$$anonymous$$ Unloading 87 unused Assets to reduce memory usage. Loaded Objects now: 986. Total: 30.087999 ms (FindLiveObjects: 0.383208 ms CreateObject$$anonymous$$apping: 0.078083 ms $$anonymous$$arkObjects: 2.247333 ms DeleteObjects: 26.832251 ms)

2015-04-14 16:04:41.863 xxxxxxx[1832:491408] Communications error: { count = 1, contents = "XPCErrorDescription" => { length = 22, contents = "Connection interrupted" } }>

0 Replies

· Add your reply
  • Sort: 

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

C# and JavaScript Unstable? 1 Answer

[SOLVED] How to make a mesh with mobile/bumped diffuse shader transparent? 1 Answer

WebCamTexture IOS crashing? 1 Answer

Distribute terrain in zones 3 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