Spawnables
Last updated
Last updated
The Spawnables component is there to provide the objects that are spawned by the different effects. The class itself is not optimized as it uses Instantiate instead of object pooling, but this is on purpose. It is not (only) because I am lazy that I took that decision, but because I assume that most people already have their implementation of object pooling and that it's better to provide something that can be plugged in your implementation rather than forcing another one.
It works pretty much how you would expect, you can give it a bunch of prefab to pick from and assign them a probability, and then it will randomly pick one of those each time you call SpawnObject(). This is an example of setup, which is rather self explanatory.
If you'd go about plugging in your object pooling in there, you could just modify the class so that instead of having "ObjectToSpawn", you'd give it your object pool. Then modify the very last line of the script into whatever your object pooling is defined:
Then you'll also need some work to make sure that the object are not Destroyed in the effects you create but rather put back in the pool, I'll leave this up to you as you might probably just create your own effects.
The Locked property doesn't prevent you from changing the probability, but prevents the code from doing so. The code is always going to try to keep the probabilities adding up to 1, but you can break that if you move around too much the locked values.
However even if you get a sum of probability above 1, it will be normalized by the SpawnObject() method so there shouldn't be any unexpected behavior, but it's good that you know about it.