Once Action Is Completed Wait to Do It Again Unity

Video games are loop-driven applications, meaning that some code executes before a frame draws to the screen. As a result, games often have many things to process in simply a fraction of a 2nd. If anything takes longer than a few milliseconds to consummate, the frame rate drops and creates a poor thespian feel. No one likes choppy gameplay!

But sometimes, it's unavoidable for tasks to have longer than a few milliseconds to complete. This is where asynchronous programming can actually come in handy. You can kickoff processes in parallel, allowing the user to go on with their game.

In this tutorial, you'll create Wenderlich-Topia, a town-edifice game that allows users to construct roads and houses asynchronously.

Wenderlich-Topia game in action

In the procedure of building the game, you'll learn how to:

  • Build roads with basic asynchronous methods.
  • Trigger deportment one time the build process is complete.
  • Build houses with multiple asynchronous methods, returning the structure costs once builds complete.
  • Cancel asynchronous build methods.
  • Handle errors and catch exceptions.

You'll demand Unity 2020.3 or later to build the game.

Annotation: This tutorial assumes you sympathise the fundamentals of working with C# and Unity. If you demand to familiarize yourself with Unity, read the Get Started with Unity tutorial before proceeding. If you need a C# primer, so you should check out Get-go Programming with C#.

Getting Started

Download both the starter and last projects by clicking the Download Materials button at the top or bottom of the tutorial.

Explore both projects and familiarize yourself with the setup. In the true spirit of asynchronous programming, you could likewise explore the projects in parallel with working on the tutorial. :]

Setting Up the Starter Project

Open the starter project in Unity and navigate to the Assets/RW folder. Here are the subfolders you run into and what they incorporate:

  • Sound: Background music and the greenbacks register sound effect.
  • Prefabs: Consummate and fractional structures that get built in the project.
  • Scenes: Wenderlich-Topia demo scene.
  • ScriptableObjects: Data for the structures that you lot'll build.
  • Scripts: Scripts for all game logic.
  • Sprites: Sprites for all isometric art avails.

Open up the demo scene located in the Assets/RW/Scenes/Wenderlich-Topia project binder. Prepare the attribute ratio of the Game View to sixteen:9 Attribute and then the UI displays correctly.

setting the aspect ratio to 16:9 for the Game View

Click Play to first the game. Yous'll encounter the Welcome UI. Click the "10" icon to close the welcome message and observe the starting scene.

wenderlich-topia game starting screen

Advantages of Asynchronous Programming

The principal reward of asynchronous programming is that y'all tin can run multiple tasks simultaneously without blocking the overall execution of the current thread. In Unity, unless you lot're getting into the Chore System, most gameplay code is synchronous. That is, the code executes sequentially — i line, one instruction at a time. Once a task is finished, another one begins. Generally, this works fine but non e'er.

For example, in the sample project, a road can take a few seconds to build. If the code were purely synchronous, the thespian would take to look for the route to terminate building before doing annihilation else. Building a city would take a lot of time!

This is where asynchronous programming can help.

Writing Bones Asynchronous Code

Using asynchronous lawmaking, you'll allow players to build multiple houses and roads in Wenderlich-Topia asynchronously.

Kickoff, you'll ascertain an entry point to serve equally a bridge betwixt synchronous and asynchronous code. So, you'll define specific tasks that run asynchronously. And finally, you'll write sections of code that will run in one case your tasks are complete.

To summarize the game's construction loop:

  1. Player selects a blazon of structure from the menu.
  2. Player clicks on the map where they want to place it.
  3. A temporary structure tile spawns where the structure will go.
  4. The program takes some time to build the structure.
  5. One time time is upward, the program replaces the construction tile with the finalized road or house tile.
  6. The program plays a UI effect to display the price of construction and adds it to the total metropolis price.

Note: Some of the behaviors listed above already exist in the starter project. Yous tin cheque out the StructurePlacementManager.cs and UiManger.cs scripts to encounter how behaviors 1, 2 and 6 work. You volition, notwithstanding, implement behaviors 3-5 later in the tutorial.

Defining the async Keyword

The keyword async, as you might have guessed, defines a method that can run asynchronously. async goes between the admission modifier (public, private, etc.) and the return type.

To define async, open RW/Scripts/Managers/ConstructionManager.cs in your editor of selection. Add async to BuildStructure on line 48. Your BuildStructure method should at present look like this:

public async void BuildStructure(GameObject placementStructure, Vector3 buildPosition) {     // Method code goes hither }        

This method serves as the entry bespeak into the remaining asynchronous code y'all'll implement in this projection. This entry point tin can await the completion of other asynchronous methods earlier proceeding.

Take annotation of the async method's return blazon. (In this method'due south case it is void). Methods tagged with async can have one of three return types: void, Task and Task<TResult>. All three return types will exist covered in this tutorial.

Avoid using void equally a render type for async except for result handlers or as an entry signal into asynchronous code. This is because, while async void tin can await for asynchronous methods to complete, other methods tin can't look for async void to complete, and will continue executing, leading to unexpected and out-of-society code execution.

Additionally, async void can't grab exceptions in the same way async Task can. You lot'll larn to catch exceptions later in this tutorial. For at present, start building some structures in Wenderlich-Topia.

Building Structures With Task

By now you lot've seen the term Task a few times. Just what exactly does it hateful? In asynchronous programming, Task is simply a class that represents a single operation that tin run asynchronously.

An async method that returns Task cannot render any values. However, dissimilar void, Task does let you lot to cheque an operation's completion status. You tin execute lawmaking subsequently the Task method is finished.

So, to let your BuildStructure method to know when a road is finished building, you'll need a method that returns a Task. Add a new method chosen BuildRoadAsync to ConstructionManager.cs, after the existing BuildStructure method:

private async Chore BuildRoadAsync(RoadBuildProperties roadProperties, Vector3 buildPosition) {  }        

Here, the RoadBuildProperties statement is a pre-alleged ScriptableObject that contains information pertinent to the construction of the route and buildPosition is the position that the road will proceed the map.

Note: While not required by the compiler, it'south best practice to add the suffix Async to asynchronous methods, to denote them every bit asynchronous.

Placing Temporary Construction Tiles

Next, you'll start adding some functionality to the new BuildRoadAsync method. Y'all do this the aforementioned way you lot would add steps to any regular method.

For starters, yous'll place a construction tile at the location where the road will be. In BuildRoadAsync, add the following line to instantiate constructionTilePrefab at the location the user clicks.

var constructionTile = Instantiate(constructionTilePrefab, buildPosition, Quaternion.identity, levelGeometryContainer);        

Now that you've defined the start step of building a road, it's time to call the method. You call asynchronous methods the aforementioned mode you telephone call whatsoever other method. In the BuildStructure method, add the following line after roadProperties gets defined and set:

var buildRoadTask = BuildRoadAsync(roadProperties, buildPosition);        

buildRoadTask will at present concord a reference to the returned Job from the BuildRoadAsync method. Save your script.

Test if this first pace worked. Go to Unity and click Play. In play style, select ane of the roads from the build menu and place it in the game world. If everything is working correctly, you lot'll see the construction tile spawn where you placed the road.

Placing construction tiles for roads in Wenderlich-Topia

Your code is even so running synchronously. That'southward considering the program doesn't know to wait for a task'due south completion to run farther steps.

Adding await to Get-go Running Asynchronous Lawmaking

The concluding component for writing bones asynchronous tasks is await. Using information technology with a Task tells the program to return to executing the synchronous code that called the async method. This synchronous code is therefore non blocked, and tin can continue running at to the lowest degree until information technology requires the returned Task lawmaking. The async Chore will continue running in the groundwork while the residue of the synchronous application lawmaking runs. Once the async Chore method completes, the lawmaking after await will resume executing.

The above might sound confusing at start, so read it a few times. Or read this quote from the Microsoft await operator documentation:

The look operator doesn't block the thread that evaluates the async method. When the await operator suspends the enclosing async method, the control returns to the caller of the method.

In Wenderlich-Topia, roads will have some time to build, yet the histrion will expect to be able to continue interacting with the game while the route is under construction. The code will look the route's completion then that the rest of the game can continue running uninterrupted.

Once the road edifice job is complete, the asynchronous method resumes and does the following:

  • Removes the temporary construction tile.
  • Spawns the final road tile.
  • Plays a UI effect displaying the cost of the road.

To start running asynchronous lawmaking, you'll expect a call to Task.Delay(int millisecondsDelay) in the BuildRoadAsync method to allow a time delay of 2.five seconds later the constructionTile spawns. Add the post-obit to the stop of the BuildRoadAsync method.

await Task.Delay(2500);        

Now, any subsequent lawmaking in BuildRoadAsync volition not run until the 2.5 2nd timer is up.

Adjacent, remove the temporary construction tile and spawn the final route tile. To do this, add the code below after the look Task.Delay(2500); line in the BuildRoadAsync method:

Destroy(constructionTile); Instantiate(roadProperties.completedRoadPrefab, buildPosition, Quaternion.identity, levelGeometryContainer);        

The full road construction cycle is now in place. Side by side, you need to ensure that BuildStructure knows when the route is finished and then it tin can show the relevant UI effects. The UI effect for showing the total build cost is already included in the Starter projection. The UI Manager handles this responsibleness for you.

Add the code below to the BuildStructure method, subsequently the call to BuildRoadAsync, which you added previously:

wait buildRoadTask; uiManager.NewStructureComplete(roadProperties.roadCost, buildPosition);        

The game will now wait for the BuildRoadAsync to complete and then show the cost of the route as a UI upshot.

Go to Unity, enter play mode, and identify some roads in the game earth.

Building roads in Wenderlich-Topia

You lot'll see the construction tile appear. Then, later 2.5 seconds, the final road volition appear, followed past the UI effect showing the cost. Find that while the road is being built, yous can nonetheless collaborate with the game and even build multiple roads at once if yous're fast enough. :]

Quickly building roads in Wenderlich-Topia

Further Asynchronous Programming Concepts

In the following two sections, yous'll learn some more asynchronous programming features by building houses. In the end, residents of Wenderlich-Topia will have a place to live.

To build a firm, implement the following steps:

  1. Place a temporary structure tile where the house volition go built.
  2. Build a firm frame.
  3. Build a roof.
  4. Build a debate.
  5. Finalize the house.
  6. Play UI effect to display final toll.

Steps two-4 are individual tasks, but they won't happen in sequence. Once yous construct the frame, you tin can also construct the roof and contend at the same time. One time both the roof and fence are consummate, you tin can finalize the business firm.

Returning Values From Tasks

Remember the three types of return values you learned about earlier? In the following section, you'll learn how to use the third type, Task<TResult> to return values from Tasks.

1 primal deviation between building houses and roads in Wenderlich-Topia is the toll. The thespian won't know the final cost of building a house at the time of construction, just they will know the estimated toll shown on the Build House UI push.

In ConstructionManager.cs, ascertain a BuildHouseAsync method to schedule individual tasks. Each task calculates the task cost by multiplying the task completion time by a wage value. At the terminate of BuildHouseAsync, you lot'll:

  • Sum the cost of all tasks.
  • Return the full price to BuildStructure.
  • Display the total cost UI consequence.

Note: For this project, each task will take a random amount of time between ane.5 and 3.25 seconds. The wage is set at $thirty.

You'll at present implement the method that returns Chore<TResult>. This return type has the same features every bit a standard Task, with the important benefit of being able to render a defined value within the angle brackets. Like a standard non-void method, async Job<TResult> must return a value of the defined type.

Now, define the BuildHouseAsync method that returns a Chore<int>, every bit the total house cost volition be represented as an integer type:

private async Task<int> BuildHouseAsync(HouseBuildProperties houseBuildProperties, Vector3 buildPosition) {     var constructionTile = Instantiate(constructionTilePrefab, buildPosition, Quaternion.identity, levelGeometryContainer);      return 100; }        

The method spawns the temporary construction tile and returns a value of $100. The value is temporary. Yous'll summate the actual value of the firm in one case information technology'southward finished. Too bad because a $100 house would definitely be a steal.

Next, in BuildStructure, make a call to BuildHouseAsync after y'all set houseProperties. Store the effect every bit a Job, and so look until it's complete:

var buildHouseTask = BuildHouseAsync(houseProperties, buildPosition); look buildHouseTask;        

Next, in the same method, calculate the toll of the firm by accessing Issue on buildHouseTask. You lot'll utilise that value to display the UI consequence on the screen.

var houseCost = buildHouseTask.Result; uiManager.NewStructureComplete(houseCost, buildPosition);        

Return to Unity, enter play mode, and effort to build a new business firm in the game world. Outset, you'll run across the temporary construction tile placed on the map, immediately followed by the UI event displaying $100, the placeholder price.

Placing temporary tiles for houses in Wenderlich-Topia

Pending Multiple Tasks

Next, you'll create tasks for edifice each piece of the house. Luckily, the steps to build the house are withal, so you tin can ascertain ane task to use for all of them, passing in a different prefab for each type.

In the ConstructionManager.cs script, define a new method, BuildHousePartAsync, which will return a Task<int> (the integer value of the cost):

private async Task<int> BuildHousePartAsync(HouseBuildProperties houseBuildProperties, GameObject housePartPrefab, Vector3 buildPosition) {     var constructionTime = houseBuildProperties.GetConstructionTime();     wait Job.Delay(constructionTime); }        

This method gets the time it takes to build a certain part, and so waits for the specified duration. After the delay, that office of the business firm is consummate. You may exist curious how the delay is calculated. Well, that is a helper property that is defined on the HouseBuildProperties.cs ScriptableObject which is included in the project files.

public int GetConstructionTime() => Random.Range(minConstructionTime, maxConstructionTime);        

After defining the BuildHousePartAsync method you may notice an error in your IDE. (Non all lawmaking paths return a value). That'due south considering the BuildHousePartAsync method isn't returning a value yet simply you take declared it with a render blazon of Task<int>. You lot'll add this side by side.

In the aforementioned method after wait Task.Delay(constructionTime);, spawn the housePartPrefab and calculate the price of the task. Then, return that cost as an integer.

Instantiate(housePartPrefab, buildPosition, Quaternion.identity, levelGeometryContainer); var taskCost = constructionTime * houseBuildProperties.wage; render taskCost;        

In the lawmaking block above, you're:

  • Calling Instantiate to instantiate a new GameObject based on the relevant house part prefab and placing it as the correct location.
  • Calculating the toll by multiplying the constructionTime by the set wage.
  • Returning the calculated cost as an integer.

Building a House by Parts

Now that y'all take sufficient logic to build each part of the business firm, yous need to ascertain the tasks for each of these parts: frame, roof and fence. Call await for the tasks within BuildHouseAsync afterwards the construction tile spawns, and before the render call.

Beginning with the frame of the house. You can't start other tasks until the frame is complete, so any subsequent code volition expect the completion of this chore:

Task<int> buildFrame = BuildHousePartAsync(houseBuildProperties, houseBuildProperties.completedFramePrefab, buildPosition); expect buildFrame;        

Next, you can begin edifice the roof and argue. These tasks can take identify at the aforementioned time, so don't await anything only even so. Add together this lawmaking immediately after the previous block you simply added (in the same BuildHouseAsync method).

Job<int> buildRoof = BuildHousePartAsync(houseBuildProperties, houseBuildProperties.completedRoofPrefab, buildPosition); Task<int> buildFence = BuildHousePartAsync(houseBuildProperties, houseBuildProperties.completedFencePrefab, buildPosition);        

The final pace of building the firm is to finalize the business firm. Withal, yous tin't start this step until both the roof and fence are done. This is where yous'll learn a new technique – how to await multiple Tasks.

Add this line later the definition of the previous two tasks you but added in BuildHouseAsync:

expect Chore.WhenAll(buildRoof, buildFence);        

Job.WhenAll(Task[] tasks) will look until all divers tasks are complete. In this case, the code will go along executing once both the roof and argue are up.

At present, in the aforementioned method, telephone call and expect a job to finalize the house. This chore will place down the final, completed house prefab.

Chore<int> finalizeHouse = BuildHousePartAsync(houseBuildProperties, houseBuildProperties.completedHousePrefab, buildPosition); wait finalizeHouse;        

Cleaning up Construction

After the previously added code runs, the business firm is consummate. The side by side steps are to destroy the temporary construction tile, calculate the total house cost, render the result and remove that temporary render value of $100. You'll use Task.Result to get the price of each chore. Add the below code to BuildHouseAsync past replacing the existing return 100; line with:

Destroy(constructionTile);  var totalHouseCost = buildFrame.Result + buildRoof.Result + buildFence.Result + finalizeHouse.Effect; return totalHouseCost;        

And that's all information technology takes to build a business firm. In this game, at least… :]

Now, go back to Unity, enter play mode, and test building some houses. You lot'll know everything is working if y'all have a business firm at the end with a roof, a frame and a contend around it. You tin can refer to the code in the final project files in example you lot are stuck.

Building houses in Wenderlich-Topia

Look closely, and you'll see that sometimes the contend finishes before the roof, and other times, information technology's the other way around. If yous're really lucky, the 'builders' (a.one thousand.a. random time returning Tasks!) are synchronized, and they complete at the same time.

Improving Your Asynchronous Code

At present that yous know how to write basic asynchronous code, you need to make some considerations to make your asynchronous lawmaking safer and more than flexible.

Cancelling Tasks

You need to consider how to handle task cancelation considering there may be an occasion when you need to stop an active task. For instance, yous may want to add together a feature that allows the player to cancel a edifice's construction. Or if you're running the game in the Unity Editor and you lot stop the projection from running. Spoiler alert: you'll actually implement both of these features! :]

Replicate this use case by going back to Unity and running the awarding. Begin building a house, then get out play style earlier the house is finished building.

Exiting play mode before house is built still results in the house getting constructed

Yous'll detect something foreign happens. Even while the game isn't running, the business firm is still being built. You'll even see these new objects in the scene hierarchy, even when it's not in the play mode. I bet yous didn't think this could ever happen. :]

Scene hierarchy after stopping the game midway through construction

Since you don't desire this to happen to your players, you'll need to put in a measure that volition allow your game to cancel tasks.

Note: If you lot tried the magical "GameObject spawning whilst Editor is stopped" scenario above, before continuing, delete the spawned objects in this step from the scene Hierarchy. You'll find the spawned house parts as a child of LevelGeometry, the UI consequence as a child of UI > WorldSpaceCanvas and the sound effect as a child of Managers > BackgroundAudio, as highlighted in the screenshot in a higher place.

Cancelling a Chore Efficiently

To cancel a Task partway through execution, you'll demand a CancellationToken. In the ConstructionManager.cs script, declare a individual CancellationTokenSource so initialize it in Start.

private CancellationTokenSource cancellationTokenSource;  private void Start() {     cancellationTokenSource = new CancellationTokenSource(); }        

Now that the variable is declared, get a reference to CancellationToken in the beginning of BuildStructure like beneath:

var cancellationToken = cancellationTokenSource.Token;        

Alter the signature of all three async Task methods to take in a CancellationToken as the last parameter. For case, BuildRoadAsync should look like this:

private async Task BuildRoadAsync(RoadBuildProperties roadProperties, Vector3 buildPosition, CancellationToken cancellationToken)        

Do the same for BuildHouseAsync and BuildHousePartAsync.

Next, modify the calls to each of these methods to pass in the cancellationToken. At that place are two such calls in BuildStructure, and four calls in BuildHouseAsync. Equally an example, for the call to BuildRoadAsync, yous'll pass in the new cancellationToken like this:

var buildRoadTask = BuildRoadAsync(roadProperties, buildPosition, cancellationToken);        

Similarly, y'all demand to update the calls for BuildHouseAsync in BuildStructure and BuildHousePartAsync in BuildHouseAsync.

Finally, pass the cancellationToken into the two Chore.Delay calls. As an example, here is what you'll practise in the BuildHousePartAsync method:

await Task.Delay(constructionTime, cancellationToken);        

Find and update the Task.Delay call in BuildRoadAsync too.

Now that the CancellationToken is everywhere information technology needs to be, cancellationTokenSource needs to be used when it is time to actually cancel a task(s). Add the following line to the OnDisable() method:

cancellationTokenSource.Cancel();        

OnDisable() is always called when the application stops. (for example, when you lot stop the game in the Unity Editor). Doing this will cancel any currently running job that passed in the CancellationToken reference.

Become dorsum to Unity, enter play mode, and beginning building a house. Exit play mode earlier the firm is finished, and you'll see that no actress objects spawn exterior of play fashion.

Building houses in Wenderlich-Topia without any extra objects spawning outside of play mode

But what if the user wants to cancel a task halfway through? Let them! Using CancellationToken, a user will be able to cancel whatsoever Task while the application is still running. Every bit the welcome UI says, the user can press the Escape cardinal to cancel placing a construction. You can attain this functionality by adding the following code to the Update() method:

if (Input.GetKeyDown(KeyCode.Escape)) {     cancellationTokenSource.Abolish();     cancellationTokenSource.Dispose();     cancellationTokenSource = new CancellationTokenSource(); }        

Now, when the role player presses Escape:

  • CancellationTokenSource cancels whatever tasks that references its token.
  • CancellationTokenSource is disposed of.
  • A new CancellationTokenSource is created.

Render to Unity and run the game. Place a firm or a route on the map, then press Escape. Structure stops immediately.

Building houses in Wenderlich-Topia

Catching Exceptions

When you lot pressed Escape, you lot may have noticed that an exception showed up in the debug console. This is considering whenever a task gets canceled at runtime, an exception is thrown past CancellationToken.

Async cancellation exception

In this section, you'll learn how to take hold of these exceptions and implement your own custom mistake handling for canceled tasks. This is easy to practise using CancellationToken.

In the BuildStructure method, surround the calls to BuildRoadAsync and BuildHouseAsync in a try...catch block. Here'south what the code should look similar once wrapped in a try...catch cake for the BuildHouseAsync Task. (Don't forget to practise the BuildRoadAsync one too):

var buildHouseTask = BuildHouseAsync(houseProperties, buildPosition, cancellationToken);  try {     await buildHouseTask;     var houseCost = buildHouseTask.Consequence;     uiManager.NewStructureComplete(houseCost, buildPosition); } grab {     Debug.LogWarning("Building Firm Cancelled"); }        

The job is now pending within try. If it completes successfully, the remaining code in try will run, displaying the appropriate UI effect. If Task throws an exception through CancellationToken, the code inside grab will run instead. For simplicity and the purposes of this tutorial, a alert is printed to the console. For your ain project, you might desire to handle this in a better style.

Become dorsum to Unity, enter play way, and test your exception catching. Cancel a firm halfway through its building process. Rather than a system-generated fault, you now encounter the custom warning you printed through lawmaking.

Async cancellation warning

Choosing Asynchronous Programming vs. Coroutines

At present that you've learned about C# asynchronous methods, you might take found similarities to coroutines in Unity. However, while they are similar, key differences between the ii brand each of them work better in certain situations.

Coroutines are a type of method that allows lawmaking to be executed over a stretched period of time. Often, programmers use coroutines for moving GameObjects, setting countdown timers or fading textures between colors. Basically, they suit gameplay programming quite well.

You tin can larn more about how to apply coroutines in the official Unity documentation.

Advantages of async Over Coroutines

One of the biggest advantages of async over coroutines is its ability to render values. For example, in Wenderlich-Topia, the cost of building the firm is calculated asynchronously while the house is being built. Once the business firm is consummate, the code returns the total price of the house's value, and the result is available in the Task result variable. Coroutines tin't render whatever values.

Async methods can too run on threads that aren't the main thread. This ways they tin can continue working on complex tasks without impacting performance on the main thread.

While coroutines too run in the background, they run on the chief thread. This means they could bear upon the performance of the game if they're doing complex operations.

Finally, a major advantage of async is that many external libraries and APIs also apply async. This makes information technology easy to integrate others' asynchronous methods into your code.

Deciding When to Use Coroutines

Coroutines are best used for set it and forget it scenarios when you need to execute code over time but don't need any results and don't want to manage your code. Once the coroutine is complete, it tin trigger some boosted behaviors to happen. (An example of this beingness the one described before – irresolute the colour of a GameObject over time).

Additionally, because coroutines are a Unity characteristic, they'll cease when the program ends. You won't have the same problem with asynchronous code, which would go along running even later on the application stops. Unity handles this cancellation for you. Equally you saw earlier, the Unity engine does not handle the cancelation of async Tasks.

Coroutines also integrate well with other Unity features and a game'southward update loop. With coroutines, you can just call yield return break; to halt a method'southward execution and return to that point in the method on the next frame. Put a yield within a for or while loop and y'all can make things move or change over time.

Y'all can achieve like behavior with async in Unity, simply of course, being a C# language feature, information technology wasn't built with this use case in listen, so the lawmaking is a bit messier when trying this kind of scenario with Unity.

Where to Go From Here?

You can apply the Download Materials button at the superlative and bottom of this tutorial to download the starter and final projects.

Now, y'all hopefully understand how to use asynchronous methods in Unity and know when to utilize them (and when non to).

To increase your skills, practice implementing what you learned in some of your own projects.

As a next stride, you could graduate to integrating with other asynchronous features such as Unity's Addressable Asset System. This asynchronous way of loading assets into your game is preferable to loading assets from the Resources folder. For more information on the Addressable Asset Organization, check out Introduction to Modding Unity Games with Addressables from raywenderlich.com.

You tin can besides learn about writing multithreaded code using something like Unity's C# Job System. Check out the raywenderlich.com tutorial Unity Job Organization and Burst Compiler: Getting Started on how to create a wave generator using Unity'south C# Job System.

We hope you enjoyed this tutorial. If you accept whatever questions or comments, please experience free to join the forum discussion below!

macmahonpriny1982.blogspot.com

Source: https://www.raywenderlich.com/26799311-introduction-to-asynchronous-programming-in-unity

0 Response to "Once Action Is Completed Wait to Do It Again Unity"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel