Skip to main content

Questions tagged [coroutines]

Coroutines are software components that generalize subroutines for cooperative multitasking. They are suited for asynchronous (or non-blocking) programming and allow program execution to be suspended and resumed.

Filter by
Sorted by
Tagged with
0 votes
0 answers
35 views

Tried to queue enemy attacks but they attack too fast and simultaneously

I'm newbie with programming and Unity. I was trying to make a queue for the second enemy to attack only when the first finishes its attack, but it just doesn't work: they attack much much faster and ...
Daniel's user avatar
  • 1
0 votes
1 answer
36 views

WaitForEndOfFrame in a loop is not updating the inspector

My code has a function ...
Usylom's user avatar
  • 31
0 votes
1 answer
98 views

Why doesn't Coroutine work the way I want with if blocks?

I'm making a game and when the enemy dies I keep it in memory. I want the person playing to find the game just as they left it when they enter. I'm doing most of these, but there's one small problem ...
Volkan AKDAG's user avatar
1 vote
0 answers
115 views

How to use await with GDExtension-wrapped external library functions?

I am looking at wrapping functionality from an external C++ library with GDExtension for use with Godot 4. Many of these functions have an appreciable runtime before they return the values of interest,...
R.M.'s user avatar
  • 141
-2 votes
1 answer
86 views

How to make a coroutine private in Unity?

I am trying to make a coroutine private in Unity. I have tried declaring it as a private method, but it still seems to be accessible from other classes. Here is an example of the code I am using: <...
Alex Junior's user avatar
1 vote
1 answer
140 views

Audio won't pause in coroutine

I am making a system where I have one long audio clip made up of voice lines which I want to be able to play one after the other with a variable pause in between. I press the space key to start the ...
Michael's user avatar
  • 51
0 votes
1 answer
111 views

Moving Multiple Objects With Vector2.MoveTowards Not Consistent

Good Afternoon, I'm trying to move three objects from their current position to a shared target position based on speed. Once they reach the target position, they move to a shared respawn location and ...
PayasoPrince's user avatar
0 votes
3 answers
381 views

Coroutine delay isn't consistent on different framerates

My problem: I am using a coroutine to add a typewriter effect to my texts, but the delay (using yield return new WaitForSeconds();) isn't consistent on different ...
DemonicTree's user avatar
11 votes
1 answer
4k views

Are there limits to the number of coroutines in Unity?

While reading a thread about coroutines, I stumbled upon a random user's comment that coroutines may not fire at all: Just so you are aware, there is a coroutine limit and if you hit this some ...
Saturn's user avatar
  • 1,763
0 votes
0 answers
274 views

how do i get my coroutine to update every frame in my BepInEx plugin?

in the code linked below, i am using bepinex and harmony to make a plugin for the game Sons of The Forest the goal of the code attached is to log the value of an in-game variable every second, but the ...
naenae baby's user avatar
0 votes
1 answer
131 views

Can player input be missed while yielding WaitForSeconds?

I just wanted to fact check myself on a scenario where the player may be locked out of input. With this example, there is a chance that the player's input will not be received if they happen to press ...
PayasoPrince's user avatar
0 votes
2 answers
2k views

How to deal damage every 2 seconds while enemy is touching the player, rather than every frame?

I have made an up and down movement RPG prototype and I wanted to have a fighting system. I made it so that the enemy follows the player and that I get damage every time he collides with me. The ...
Hammynator's user avatar
0 votes
0 answers
874 views

Is there a way around using yield return null for coroutines to avoid waiting an extra frame at the end of my coroutine?

I've gotten used to using coroutines as a way to ensure a things are done sequentially in my code, i.e. instead of calling method a, method b, and method c on back to back lines I will sometimes yield ...
Kyle34562345's user avatar
0 votes
1 answer
410 views

Deal damage just once, rather than repeatedly till the enemy dies

I am new to making games with Unity. I am trying to damage the enemy. So far, the damage works. The problem is it will repeat it until the enemy is dead, but I want it to damage the enemy only once. <...
Spectral's user avatar
0 votes
1 answer
448 views

Unity coroutine not yielding sometimes

I'm making a 2D platformer controller and I want to implement a coyote time and buffered jump, the way I implement both is by setting a bool to true when either action is enabled like this: ...
lsauceda's user avatar
  • 151
0 votes
0 answers
375 views

Unity Coroutine freezes game even though no loop

Every time I call this function that starts the coroutine Faint, it freezes the game. I do not understand why this freezes the game though, because the coroutine does not have any loop. ...
UserUser's user avatar
  • 171
0 votes
1 answer
160 views

How to change animation coroutine when a variable changes, not every frame?

I want to be able to change the enum animation mode at runtime. This way will start the coroutine every frame in Update, but I want to start the coroutine only if the value of the enum variable has ...
Daniel Lip's user avatar
  • 1,757
0 votes
2 answers
833 views

How does a "static" IEnumerator work in this context? (The code works, but what is it actually doing?)

I am generating many objects procedurally in my Unity C# app/game such as user interfaces, user profiles, etc. I have made classes which feature static variables/functions to allow this. Everything ...
mike's user avatar
  • 501
0 votes
2 answers
104 views

Why coroutine gets stopped?

Here's my code: ...
Arian_ki's user avatar
  • 691
0 votes
0 answers
37 views

Gun keeps firing before the player is finished rotating

I have a script that manages player rotation and shooting. When I click on an enemy, the player is supposed to turn toward the enemy and then shoot in the direction they are facing. However, the ...
SethD02's user avatar
1 vote
0 answers
216 views

"Assertion failed" error when running coroutines in edit mode - Unity

TLDR: Calling coroutines from OnValidate in edit mode leads to following error: ...
arcadeperfect's user avatar
-1 votes
2 answers
1k views

Why can't I stop Coroutine?

...
Khanh's user avatar
  • 1
0 votes
0 answers
47 views

How to change fall delay of a gameobject by time?

I want my gameobjects to fall faster by time as the player collides with them. What I mean is, when the game starts, the gameobjects fall off after 1 second the player collided with them, but after 60 ...
imbruceter's user avatar
0 votes
1 answer
204 views

Triggers VS coroutine performance?

So I am using unity and wondering if I have an agent going to move to a position say Agent A moves to position B in x seconds guaranteed (avoids all physics or things that could disrupt the path). ...
Doug Ray's user avatar
  • 143
1 vote
1 answer
398 views

Wait for a function to return value without impacting framerate

I'm looking to do some possibly heavy calculation in my game. An agent in my game needs to evaluate up to 1000 objects while performing heavy calculations to select his next job. I want to either ...
caleidon's user avatar
  • 591
0 votes
1 answer
346 views

check if joystick magnitude is increasing

I use joystick mechanic. What I want to do is: Translating my object forward when my joystickInput.magnitude is increasing. Translating backward when my ...
anónimo's user avatar
0 votes
0 answers
8 views

How to temporarily set a game object active? [duplicate]

I'm trying to an use IEnumerator method called Wait() to temporarily enable and then wait, and disable a gameobject within a method. Basically I'm trying to create a muzzle flash within a shoot method,...
SethD02's user avatar
0 votes
1 answer
219 views

Using Lua to define NPC behaviour

I'm working on a RPG in C using Lua for event scripting like NPC behavior. I ran into a design problem. I have created Lua threads in the C API for each game object which can be a NPC. So this: ...
Michael Muniko's user avatar
0 votes
2 answers
158 views

Unexpected Result On Coroutines Called From Another Script

So I performed tests on calling coroutines from another script. I want to understand why the results aren't the expected behavior in one of the test case, and unfortunately the one that I needed to ...
Kintaro's user avatar
  • 131
0 votes
2 answers
349 views

How to fix issues with repeated coroutines for lerping values?

I have created a progress bar system that lerps the value over a duration to provide some life to the progress bars. I've done this using a coroutine that gets called each time a value (such as life ...
MKorialstrasz Krasus's user avatar
1 vote
1 answer
329 views

Design pattern for menu transitions in C# (Unity)

I am working on my first project in Unity using C# and I am currently trying to design a menu system that does the following sequence of events when a user clicks a button: Button does some effect ...
DyingIsFun's user avatar
  • 1,317
0 votes
1 answer
1k views

Unity3D: Download multiple files and implement a callback

...
MrRobot9's user avatar
  • 331
11 votes
2 answers
15k views

Should I use Async & Await, instead of Coroutines, in Unity?

Should I use Async & Await in Unity? Or should I keep using Coroutines? If I should use Async & Await, how can I do so in a manner comparable to Coroutines?
Evorlor's user avatar
  • 5,840
0 votes
3 answers
931 views

How can I stop and resume a coroutine over and over again?

I want a coroutine to enter by default and then to stop when any input is given to it but then after some code to return again as active. So basically to start and stop a coroutine as many times as it'...
RODOR's user avatar
  • 5
0 votes
1 answer
70 views

Unity: How to connect to server with status in dialog

I am trying to build in unity a basic logon screen. Now I'm building on something if the connection will have delay or so... There will be a dialog, where the progress of connection to server will be ...
Zechy's user avatar
  • 67
0 votes
0 answers
11 views

Coroutine problem, I don't know what's happening [duplicate]

Calling function. ...
IndividualGames's user avatar
0 votes
1 answer
518 views

How to call StartCourotine in abstract class?

Bellow is my code. I have an abstract class and a inheriting class. This keeps giving me an NullReferenceException, on the ...
ManoTech's user avatar
  • 157
0 votes
0 answers
30 views

FixedUpdate or Subroutine

So Update is called every frame while FixedUpdate is called on Physics time, which can be modified. Is it better to depend on FixedUpdate to have optimized game loop so that everything doesn't get ...
IndividualGames's user avatar
0 votes
1 answer
68 views

Unity both duration and cooldown system

I have a boss with machine gun and i am trying to make him shoot for 5 seconds and then stop for 5 seconds and so on. I tried to create an IEnumerator and call it on Start (as far as i know i can not ...
funtar's user avatar
  • 5
0 votes
1 answer
900 views

How to start a coroutine that will finish after the object is destroyed

I have a simple game in which the player can collect power-ups. Each power-up gives the player a temporary advantage for several seconds. The power-up should disappear immediately after the player ...
Erel Segal-Halevi's user avatar
0 votes
1 answer
307 views

How to batch coroutines (IEnumerators) in parallel

We are working in a context where multithreading is not an option, so we're using coroutines to handle our loads. Often there are multiple things that need to be downloaded, leading to a pattern like ...
FlintZA's user avatar
  • 293
0 votes
1 answer
69 views

Unity Can't adjust firing rate

I need to be able to control the speed in which the gun fires. I'm trying to use the couroutine to limit the speed of update method but it doesn't work for some reason. I've tried several fireRate ...
IndividualGames's user avatar
1 vote
1 answer
5k views

How to restart a coroutine

I want to run my code multiple times without using the Update() method, now, I could use a coroutine or an Invoke(), but since the Invoke() is not very performance friendly as a coroutine, my best ...
Gozmetaiemax's user avatar
0 votes
3 answers
849 views

Why does my recursive coroutine freeze Unity?

I want the bounds (left wall and right wall) to follow the player's y position, a couple of times. However when I use this code, Unity freezez as soon as it runs, and I have to manually shut it down. ...
ZozeR's user avatar
  • 42
1 vote
1 answer
113 views

Coroutine only partially executing

I have a Coroutine that I use to pull and spawn an enemy in my game. This coroutine works perfectly fine, with the exception of the very first call. I am fairly certain this is because I am probably ...
Sainath Krishnan's user avatar
0 votes
1 answer
2k views

How to make progress bar in EditorWindow with Threading in Unity?

I need to make a progress bar in EditorWindow. To do this, I perform the function of calculations in threads: Thread thread = new Thread (_worker.Work); thread.Start (); The class itself emitting ...
Ivan Triumphov's user avatar
1 vote
1 answer
165 views

Unity, WaitUntil in a self-made message box class

I managed to make a simple message box prefab with a Text and a Button through Canvas, and ...
PiggyChu001's user avatar
8 votes
6 answers
5k views

Why am I not getting stuck in the loop

I'm new to Unity. I was learning coroutines and I wrote this. ...
babybrain's user avatar
0 votes
2 answers
1k views

Is coroutine as good as a delay() function [closed]

I'm new to Unity and I was learning the usage of coroutines. Is calling a coroutine as good as a delay() function? Does Unity have a delay() function?
babybrain's user avatar
0 votes
1 answer
64 views

Bullet prefab gets stuck to target after hitting

As the title says, I am having an issue with prefabs: I am trying to make a bullet follow a curve and then hit a target using this method: ...
FSic's user avatar
  • 176