• 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 shortyzsly · Sep 24, 2014 at 05:17 PM · triggerfpslagtriggers

Triggers causes scene to lag

Hi, My name is Dave. I have been working on a Unity based Horror for quite sometime now and all is well so far i have received good feedback however recently decided that some room doors would be shut and you would walk into them (they have trigger colliders) and my script that's attached to each door would play the audio (door opening sound), fade out the current scene and load the Scene declared in the scripts variable. And then ultimately fade in the next scene and so on you get the idea. Many doors have these triggers placed closely on front of them. but since i have put them there my scene lags alot. Even with occlusion culling throughout it. and static batching. I have tested this theory by simply disabling all triggers and then playing. The triggers go, the lag goes.... simple....

here's a copy of my script:

 public var fadeOutTexture : Texture2D;
 public var fadeSpeed = 2.0;
 var drawDepth = -1000;
 var alphaWait : boolean = true;
 
 
 public var levelName ="SceneName";
 var delayTime : float = 1.5;
  
 private var alpha = 1.0;
 private var fadeDir = -1;
 
 function OnTriggerEnter(other : Collider)
 {
         audio.Play();
         fadeOut();
         Application.LoadLevel(levelName);
         
         
         
     
 }
 
     function OnGUI(){
  
    if(alphaWait == false) {
    
     alpha += fadeDir * fadeSpeed * Time.deltaTime;
     }
    
     alpha = Mathf.Clamp01(alpha);    
     GUI.color.a = alpha;  
     GUI.depth = drawDepth;  
     GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);
 }
  
 //--------------------------------------------------------------------
  
 function fadeIn(){
  
     yield WaitForSeconds(2);
     alphaWait = false;
     fadeDir = -1;  
 }
  
 //--------------------------------------------------------------------
  
 function fadeOut(){
     fadeDir = 1;  
 }
  
 function Start(){      
     alpha=1;
     fadeIn();    
 }





Comment
Add comment · Show 2
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 tanoshimi · Sep 24, 2014 at 05:34 PM 1
Share

Are you sure it's the trigger and not the OnGUI code? (somewhat notorious for being slow)

avatar image shortyzsly · Sep 24, 2014 at 05:37 PM 0
Share

shoot! never consider that. I did have issues with OnGUI before but it never raised a flag with me..... good insight my friend thank you. So what you think i should do to rectify the problem because i have searched high and low for alternatives to OnGUI calls...

2 Replies

· Add your reply
  • Sort: 
avatar image
-2

Answer by YandereMobile · Feb 12, 2020 at 07:01 AM

Yeah duh. They're really lag. Try finding ways to not use them. For example, if your making like a stealth-game use a navmesh agent. Or Invoke the trigger;

Comment
Add comment · Show 1 · 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 Captain_Pineapple · Feb 12, 2020 at 08:54 AM 1
Share

Please do not post answers like this on questions which date back 6 years except if your answer actually brings up something new which is related to a new version of unity for example and makes other old answers obsolete...

avatar image
0

Answer by j4ke · Feb 12, 2020 at 10:16 AM

Not sure, but it might be that OnGUI causes the lagging since OnGUI causes performance costs at my knowledge. How about making the screen fade effect by using UI canvas and coroutines?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

trigger inappropriate activation 1 Answer

I have performance lag after my game has been compiled. 1 Answer

Reduce Poly Count Within Unity? Higher FPS? 1 Answer

GameObject Instanitation causing lag on webgl for mac os with chrome 0 Answers

Why my simple mobile game lags on powersaving mode? 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