Class StaticActor
This is a generic Singleton implementation for components.
Create a derived class of the script you want to "Singletonize"
public abstract class StaticActor : EActor, IEntity, IWorldSpace, IPosition, IRotation
- Inheritance
-
StaticActor
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
Do not redefine PostInitialize() OnBeginPlay() or OnEndPlay() in derived classes.
Instead, use protected virtual
methods:
PostInitialize_Static()
BeginPlay_Static()
EndPlay_Static()
To perform the initialization and cleanup: those methods are guaranteed to only be called once in the entire lifetime of the component.
Properties
IsDestroyed
Gets a value indicating whether the OnEndPlay() method has already been called by Unity.
public bool IsDestroyed { get; }
Property Value
IsInitialized
Gets a value indicating whether the PostInitialize() method has already been called by Unity.
public bool IsInitialized { get; }
Property Value
IsStarted
Gets a value indicating whether the OnBeginPlay() method has already been called by Unity.
public bool IsStarted { get; }
Property Value
Methods
BeginPlay_Static()
Fired on OnBeginPlay().
protected virtual void BeginPlay_Static()
Remarks
This method will only be called once even if multiple instances of the StaticActor component exist in the scene.
You can override this method in derived classes to customize the initialization of the component.
CreateNewInstance(Type)
Creates a new instance of the StaticActor.
public static StaticActor CreateNewInstance(Type type)
Parameters
type
TypeThe type of the StaticActor.
Returns
- StaticActor
The created StaticActor instance, or null if not found.
EndPlay_Static()
Fired on OnEndPlay().
protected virtual void EndPlay_Static()
Remarks
This method will only be called once even if multiple instances of the StaticActor component exist in the scene.
You can override this method in derived classes to customize the initialization of the component.
Flush()
Flushes the current actor.
protected virtual void Flush()
Get(Type)
Gets a StaticActor given the specified type.
public static StaticActor Get(Type type)
Parameters
type
TypeThe the type of the StaticActor to look for.
Returns
- StaticActor
The corresponding StaticActor.
Get<T>()
Gets a StaticActor given the specified type T
.
public static T Get<T>() where T : StaticActor
Returns
- T
The corresponding StaticActor, or null if not found.
Type Parameters
T
The type of the StaticActor to look for.
Get<T>(Type)
Gets a StaticActor given the specified type.
public static T Get<T>(Type type) where T : StaticActor
Parameters
type
TypeThe the type of the StaticActor to look for.
Returns
- T
The corresponding StaticActor of type
T
, or null if not found.
Type Parameters
T
The type to cast the StaticActor to.
NotifyInstanceRepeated()
If a duplicated instance of a StaticActor component is loaded into the scene this method will be called instead of PostInitialize_Static().
That way you can customize what to do with repeated instances.
protected virtual void NotifyInstanceRepeated()
Remarks
The default approach is delete the duplicated component.
OnBeginPlay()
Fired after the first fixed tick.
protected override void OnBeginPlay()
OnEndPlay()
Fired before the current EActor instance is destroyed.
protected override void OnEndPlay()
PostInitialize()
Fired after the EActor instance is created.
protected override void PostInitialize()
PostInitialize_Static()
Fired on PostInitialize().
protected virtual void PostInitialize_Static()
Remarks
This method will only be called once even if multiple instances of the StaticActor component exist in the scene.
You can override this method in derived classes to customize the initialization of the component.