Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by barmhartsam · Mar 31, 2017 at 08:36 PM · triggerontriggerenterlagframerate drops

Frame drop/lag spike ontrigger

So when I am play testing in the editor everything works fine, but when I build and launch my game I get a huge lag spike on the first trigger I enter. (It only happens on the first one). After that it works fine. The problem is that the lag spike on the first trigger is randomly break another trigger could be any...

Any idea this is happening. I don't know why I even bother asking this forum never answers.

Comment
Add comment · Show 15
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 barmhartsam · Mar 31, 2017 at 08:37 PM 0
Share

The "first" trigger can be ANY trigger it is not a specific one. I literally mean the first time you enter a trigger.

avatar image FlyingHighUp · Mar 31, 2017 at 10:55 PM 0
Share

There shouldn't be a sudden lag spike with the first OnTrigger. Have you checked this in the profiler?

avatar image barmhartsam FlyingHighUp · Apr 01, 2017 at 05:21 PM 0
Share

Thanks for replying but like I said it happens on ANY trigger as long as it is the first. I'll reply with an example trigger.

avatar image barmhartsam FlyingHighUp · Apr 01, 2017 at 05:23 PM 0
Share
 public PlayerController player;
 public GameObject jumpPanel;

 void Start ()
 {
     player = FindObjectOfType<PlayerController>();
 }    

 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Player")
     {
         player.gravity = 10;
         jumpPanel.SetActive(true);
     }
 }

 void OnTriggerStay(Collider other)
 {
     if (other.tag == "Player")
     {
         player.gravity = 10;
         jumpPanel.SetActive(true);
     }
 }

 void OnTriggerExit(Collider other)
 {
     if (other.tag == "Player")
     {
         player.gravity = 25;
         jumpPanel.SetActive(false);
     }
 }

}

avatar image barmhartsam FlyingHighUp · Apr 01, 2017 at 05:24 PM 0
Share

Where do I check in the Profiler?

avatar image toddisarockstar · Mar 31, 2017 at 11:10 PM 0
Share

please post the code attached to the trigger so we can help.

avatar image barmhartsam toddisarockstar · Apr 01, 2017 at 05:21 PM 0
Share

Thanks for replying but like I said it happens on ANY trigger as long as it is the first. I'll reply with an example trigger.

avatar image barmhartsam toddisarockstar · Apr 01, 2017 at 05:23 PM 0
Share
 public PlayerController player;
 public GameObject jumpPanel;

 void Start ()
 {
     player = FindObjectOfType<PlayerController>();
 }    

 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Player")
     {
         player.gravity = 10;
         jumpPanel.SetActive(true);
     }
 }

 void OnTriggerStay(Collider other)
 {
     if (other.tag == "Player")
     {
         player.gravity = 10;
         jumpPanel.SetActive(true);
     }
 }

 void OnTriggerExit(Collider other)
 {
     if (other.tag == "Player")
     {
         player.gravity = 25;
         jumpPanel.SetActive(false);
     }
 }

}

avatar image barmhartsam toddisarockstar · Apr 01, 2017 at 05:25 PM 0
Share

The other closest trigger is more complicated, but whether I decide to enter this trigger or the other, both decide to have a huge lag spike and do it only once.

avatar image toddisarockstar barmhartsam · Apr 02, 2017 at 01:56 AM 0
Share

adding triggers by themselves don't cause lag. It has to be some inefficiency somewhere in the code that is being triggering or something the code is changing that is causing your lag!

Show more comments
Show more comments
avatar image hexagonius · Apr 02, 2017 at 12:16 PM 0
Share

try creating a Development build with Auto attach profiler checked on player settings. run your game on the device.
make sure you have the profiler window open and it's receiving data from the device (window -> profiler).
walk into the trigger and stop tracking the data.
analyze the spike that shows up in the profiler. what's causing it?

avatar image barmhartsam hexagonius · Apr 04, 2017 at 11:00 AM 0
Share

It seems someone blocked me/my IP to respond to this question, that said this is great advice thanks I will definitely give this a go. Thank you sir, you are a saint!

avatar image barmhartsam hexagonius · Apr 04, 2017 at 11:16 AM 0
Share

alt text

So this is the spike isolated.

The culprits are Canvas.SendWillRenderCanvases() and under it, it seems Font.CacheFontForText. I do not know what to make of this though?

unityprofile.png (84.1 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Pengocat · Apr 04, 2017 at 12:19 PM

Looks like it has nothing to do with the collider but instead it is a classic example of the glyphs sheet being made when you enable the text. You can move the lag spike to the beginning of the level by caching the glyphs when the scene is loaded. Related Answer


Another trick could be to enable the panel from the beginning and instead toggle the visibilty.

Comment
Add comment · Show 6 · 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 barmhartsam · Apr 04, 2017 at 12:36 PM 0
Share

How do I cache the glyphs when the scene is loaded, because I tried toggling visibility but it is not firing when I enter the trigger. It works fine in the editor but is not triggering in the build.

avatar image barmhartsam barmhartsam · Apr 04, 2017 at 12:37 PM 0
Share

PS setting the font to OS Default in the FontImporter helped slightly.

avatar image Pengocat barmhartsam · Apr 04, 2017 at 12:48 PM 0
Share

Here is another answer trying to resolve this problem that might be useful. http://answers.unity3d.com/answers/861988/view.html

avatar image barmhartsam Pengocat · Apr 04, 2017 at 01:02 PM 0
Share

Thanks a bunch one last question - Retrieve$$anonymous$$yCustomFonts() - I do not know how to implement this or how it is supposed to be used.

Show more comments

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

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

Related Questions

OnTriggerEvent doesn't work 1 Answer

Wrong Trigger causes action to run,Multiple Triggers cause the same event 0 Answers

Trigger not detected 0 Answers

OnTriggerEnter triggers many times per trigger. 0 Answers

My Trigger detection doesn't work when i reactivate the object it's on,Detect OnTriggerEnter2D after deactivating and reactivating the object 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