Creating a new singleton
A singleton is a SimObject
instance that we only ever want one instance of. Typically we use singletons for shader objects, materials, and some audio objects. In this recipe we will learn how to create an object as a singleton.
How to do it...
Creating a singleton is straight forward. Here we will create a Material
singleton, one of a number of SimObject
classes that may be created as a singleton, as follows:
singleton Material(DECAL_scorch) { baseTex[0] = "./scorch_decal.png"; translucent = true; translucentBlendOp = None; translucentZWrite = true; alphaTest = true; alphaRef = 84; };
How it works...
We use the
singleton
keyword when creating a new SimObject
class object that we want only one instance of, and always give a unique global name to it. Other than ensuring that only one instance of this object will exist, the creation process is exactly the same as when the new
keyword was used.
See also
Creating a new SimObject instance
Creating a new internal name only SimObject instance
Creating a new Datablock object