Description
The LoadAsync
method is a static method of the Material
class in the Sandbox namespace. It is used to asynchronously load a material from a specified file. This method returns a Task<Material>
, which represents the asynchronous operation and, upon completion, provides the loaded Material
object.
Usage
To use the LoadAsync
method, call it with the filename of the material you wish to load. This method is asynchronous, so it should be awaited or handled using a continuation task.
Parameters:
filename
(System.String): The path to the material file to be loaded.
Returns: A Task<Material>
that represents the asynchronous operation. The task result contains the loaded Material
object.
Example
// Example of using LoadAsync to load a material
async Task LoadMaterialExample()
{
string materialPath = "materials/my_material.mat";
Material material = await Material.LoadAsync(materialPath);
if (material != null)
{
// Use the loaded material
Console.WriteLine($"Material '{material.Name}' loaded successfully.");
}
else
{
Console.WriteLine("Failed to load material.");
}
}