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 /
avatar image
0
Question by eduardo_cola42 · Jan 20, 2017 at 08:41 AM · c#unity 5scripting problemaicoroutine

Coroutines randomly stop working

Hello,

I'm currently working on a First Person Shooter game with Unity. I made a simple AI system for enemies which consists of a sequence which is basically:

1) Find all covers at certain range;

  • If the player is in a range of 15 meters, shoot at them;

2) Randomly choose one of them and run that way;

3) After a few random range of seconds (or when the cover is reached) stop, crouch and pick a target (either the player or an enemy NPC);

4) Aim at the target and shoot (with certain random imprecision) for a few random seconds;

5) Repeat.

I've wrapped this sequence in an IEnumerator, which is called in the Start () function and then calls itself at the end. There is also an obstacle-avoiding system, which uses a series of raycast to go around obstacles.

Everything seems to work fine and there are no Console errors. I can instantiate a bunch of enemies and they just work. But sometimes (actually almost every time I play) one or two enemies (out of 15) start misbehaving. They do not get killed (even though the colliders are working, since blood gets instantiated) and when they get to an obstacle they just keep stuck on it.

It seems so random, there are no errors in the code at all. The performance is fine (average 50 FPS) and it's not a memory problem (1.3GB occupied out of 8GB). Could it be C#/Mono? Or something related to the code? Any guesses?

Comment
Add comment · Show 1
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 EDevJogos · Jan 21, 2017 at 04:16 AM 0
Share

Have you tried to use InvokeRepeating:

https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.InvokeRepeating.html

Or even just some basic Time.deltaTime timer, just to confirm if the problem is actually with the coroutine.

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

8 People are following this question.

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

Related Questions

Can I make Money collecting script without attaching it to a object ? I tried but I got error 2 Answers

I'm trying to allow my character to only jump when grounded 1 Answer

Lerp in Coroutine (Crazy Behavior) 2 Answers

How can i avoid the enemy to sight me through walls? 1 Answer

problem with health pick up its going above the max health 1 Answer


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