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
3 votes
1 answer
148 views

I'm trying to implement a robust pause system in Unity and I'm confused about the correct approach. My first (very simple) implementation in my previous project used a ...
Curio's user avatar
  • 261
2 votes
1 answer
420 views

Consider a situation where a coroutine in node A awaits a signal from node B. If node B gets freed without sending the signal, obviously the coroutine in node A will never finish executing. Does it ...
Carl Muckenhoupt's user avatar
0 votes
1 answer
81 views

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

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
207 views

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
113 views

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
188 views

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
180 views

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
520 views

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

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
427 views

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
175 views

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

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
973 views

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
463 views

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
505 views

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
399 views

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
183 views

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,785
0 votes
2 answers
934 views

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
137 views

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

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
232 views

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

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

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
231 views

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
432 views

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
421 views

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
10 views

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
291 views

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
209 views

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
404 views

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
367 views

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,337
11 votes
2 answers
16k views

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,881
0 votes
3 answers
1k views

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
101 views

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
14 views

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

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
33 views

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
88 views

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
999 views

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
357 views

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
94 views

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

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
909 views

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
141 views

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

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
195 views

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

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

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