Jump to content

Is it possible to use GeNaSpawner.Spawn() and not block main thread?


AdamBlas

Recommended Posts

I have spawners that spawn hundreds of objects at once during runtime (trees and grass details). Each spawn takes ~500ms and is blocking the game. My question is, is it possible to somehow invoke Spawn() so that is doesn't spawn objects immediately but rather across multiple frames or in another thread?

Edited by AdamBlas
Added info that it's spawning on runtime
Link to comment
Share on other sites

Hi @AdamBlas,

Great question! If you're running into performance issues due to spawning a large number of objects at once, there is indeed a method to distribute the spawning process over multiple frames.

In the GeNaSpawner script, you can use the ScheduleSpawn() method. This method leverages coroutines to break up the workload of spawning hundreds of objects, spreading it across several frames, which should mitigate the blocking issue you're experiencing.

Here's an example of how you might use it:

GeNaSpawner mySpawner = //... get your spawner here

SpawnCall mySpawnCall = //... configure your spawn call here

//Schedule the spawning
mySpawner.ScheduleSpawn(mySpawnCall);

Remember, this method needs a SpawnCall as an argument, which you can configure to define the details of the spawn process.

Give that a try, and let me know how it works for you!

Best,
Manny

Link to comment
Share on other sites

How exactly can I configure SpawnCall object? I don't see any option to set spawn point or to specify how many object per frame to spawn.

Closest to spawn point is target, but using starndard call I can pass only Vector3, not whole transform object, so I'm not sure it is it.

Link to comment
Share on other sites

OK, my bad, don't know how I missed Location property.

Still, it doesn't work. Code looks like this:

SpawnCall spawnCall = new SpawnCall
{
	Location = tile.centerPoint,
};
spawner.ScheduleSpawn(spawnCall);

but it doesn't spawn anything. Probably need to set something else, but don't know what exactly.

Link to comment
Share on other sites

On 6/29/2023 at 9:36 AM, AdamBlas said:

OK, my bad, don't know how I missed Location property.

Still, it doesn't work. Code looks like this:

SpawnCall spawnCall = new SpawnCall
{
	Location = tile.centerPoint,
};
spawner.ScheduleSpawn(spawnCall);

but it doesn't spawn anything. Probably need to set something else, but don't know what exactly.

Hey @AdamBlas,

Thank you for your patience. Allow me to get a better example of how to use the SpawnCall.

You can call a method in a GeNa Spawner called 'GenerateSpawnCall' and configure it as necessary afterwards:
Here are all the different ones:

// Generates Spawn Call from given worldspace location.
public SpawnCall GenerateSpawnCall(Transform target, Vector3 location);

// Generates Spawn Call from given Raycast Hit information.
public SpawnCall GenerateSpawnCall(RaycastHit hitInfo);

// Generates Spawn Call from given target, location and normal.
public SpawnCall GenerateSpawnCall(Transform target, Vector3 location, Vector3 normal);

// Generates Spawn Call from given target, location and normal.
public SpawnCall GenerateSpawnCall(Transform target, Transform ground, Vector3 location, Vector3 normal)

So usage would be as follows:        

GeNaSpawner mySpawner = //... get your spawner here

SpawnCall mySpawnCall = mySpawner.GenerateSpawnCall(target, location);

//Schedule the spawning
mySpawner.ScheduleSpawn(mySpawnCall);

Let me know if you are still experiencing issues. 
I will also try to document this better in future releases. I'm currently in the process of documenting a large part of the GeNa Spawner anyways.

Link to comment
Share on other sites

HI,

unfortunetely, it's still not working. Right now, my code looks like this:

var spawnCall = spawner.GenerateSpawnCall(tile.terrain.transform, tile.centerPoint);
spawner.ScheduleSpawn(spawnCall);

Where tile.terrain is a Unity terrain component and tile.centerPoint is point right in the middle. Is there something else I should do?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
  • Need help?

    We work with some of the biggest brands in global gaming, automotive, technology, and government to create environments, games, simulations, and product launches for desktop, mobile, and VR.

    Our unique expertise and technology enable us to deliver solutions that look and run better at a fraction of the time and cost of a typical project.

    Check out some of our non-NDA work in the Gallery, and then Contact Us to accelerate your next project!

×
×
  • Create New...