This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Rendering
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
VR Development
Double Precision Coordinates
API
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

ComponentSystem Class

Header: #include <UnigineComponentSystem.h>
Inherits from: Unigine::WorldLogic

This class implements functionality of C++ Component System and is used to create, destroy, and manage components.

Notice
This class is a singleton.

See Also#

ComponentSystem Class

Members


ComponentSystem * get ( ) #

Returns a pointer to C++ Component System. This pointer must be obtained to access functions of C++ Component System:
Source code (C++)
ComponentSystem *cs = ComponentSystem::get();
// access functions of C++ Component System
...

void initialize ( ) #

Performs initialization of C++ Component System, registration of all components and creation of all necessary property files.
Notice
  • This method should me called in the AppSystemLogic::init() method.
  • If a property file for any component does not exist, it will be created automatically.
Source code (C++)
virtual int AppSystemLogic::init()
{
	// initialize ComponentSystem and register all components
	ComponentSystem::get()->initialize();

	/*...*/
	
	return 1;
}

void addInitCallback ( Unigine::CallbackBase * callback ) #

Adds a callback which is called during ComponentSystem initialization.

Arguments

void setEnabled ( bool enabled ) #

Enables or disables the C++ Component System. You can use it for performance debugging: enable or disable update(), postUpdate(), updatePhysics(), swap(), updateSync(), updateAsync() for all components.

Arguments

  • bool enabled - true to enable the C++ Component System, false to disable it.

bool isEnabled ( ) #

Returns a value indicating whether the C++ Component System is enabled. You can use it for performance debugging: check if update(), postUpdate(), updatePhysics(), swap(), updateSync(), updateAsync() are enabled/disabled for all components.

Return value

true if the C++ Component System is enabled, false if it is disabled.

int getNumComponents ( ) #

Returns the total number of components registered in C++ Component System.
Notice
This method is very slow and should not be used often.

Return value

Total number of registered components.

int getNumNodesWithComponents ( ) #

Returns the total number of nodes with components assigned.

Return value

Total number of nodes with components assigned.

template <C class>

void createPropertyFile ( ) #

Creates a property file for a registered component associated with the property with a given name.Parameters of each component are stored in a separate *.prop file. If this property file does not exist, it will be created in the data/ComponentSystem folder with a name obtained by the component's getPropertyName() method.

void initializeComponents ( constNodePtr & node ) #

Forces initialization of components associated with the given node in the currrent frame (it doesn't wait for the WorldLogic::update() callback execution).

Arguments

  • constNodePtr & node - Node for which the components need to be initialized.

void createPropertyFile ( const char * name ) #

Creates a property file for a registered component associated with the property with a given name. Parameters of each component are stored in a separate *.prop file. If this property file does not exist, it will be created in the data/ComponentSystem folder.

Arguments

  • const char * name - Name of the property associated with the component.

void createPropertyFiles ( ) #

Creates property files for all registered components. Parameters of each component are stored in a separate *.prop file. If these property files do not exist, they will be created in the data/ComponentSystem folder.

void refreshProperty ( const char * name ) #

Rewrites the *.prop file for the specified property and reloads it in the Property Manager.

Arguments

  • const char * name - Property name.

template <C class>

void refreshProperty ( ) #

Rewrites the property file for the specified component and reloads it in the Property Manager.

template <C class>

void registerComponent ( ) #

Registers a user component derived from the ComponentBase class.
Notice
  • Components must be registered in the AppSystemLogic::init() method.
  • If a property file for the component does not exist, it will be created automatically.
  • It is recommended to use the REGISTER_COMPONENT macro instead.
Source code (C++)
virtual int AppSystemLogic::init()
{
	// registering a new user component
	ComponentSystem::get()->registerComponent<MyComponent>();

	/*...*/
	
	return 1;
}

template <C class>

void unregisterComponent ( ) #

Deletes a user component derived from the ComponentBase class.

template <C class>

C * addComponent ( const NodePtr & node ) #

Adds the component to the specified node.
Source code (C++)
NodeDummyPtr node = NodeDummy::create();
node->setName("node_dummy");



ComponentSystem::get()->addComponent<MyComponent>(node->getNode());
// now the node named node_dummy appears in the Editor

Arguments

  • const NodePtr & node - Node, to which the component is to be added.

Return value

Pointer to the new added component, if it was successfully added to the specified node; otherwise nullptr.

template <C class>

C * getComponent ( const NodePtr & node, bool enabled_only = false ) #

Returns the first component of the specified type associated with the given node.

Arguments

  • const NodePtr & node - Node, for which the component of the specified type is to be found.
  • bool enabled_only - Enabled flag: true to get enabled component only, false to get component in any case.

Return value

Pointer to the component if any; otherwise, nullptr.

template <C class>

void getComponents ( const NodePtr & node, Vector<C *> & out_components, int clear_vector ) #

Searches for all components of the specified type assigned to the specified node and puts them to the given buffer vector.

Arguments

  • const NodePtr & node - Node, for which the components of the specified type are to be found.
  • Vector<C *> & out_components - Buffer vector, to which all found components of the specified type will be added.
  • int clear_vector - Flag indicating whether the buffer vector is to be cleared before adding the found components to it or not. Use 1 to clear the vector, 0 - to append new found components to the end of the vector. The default value is 1.

template <C class>

C * getComponentInChildren ( const NodePtr & node, bool enabled_only = false ) #

Returns the first component of the specified type found among all the children of the specified node (including the node itself). This method searches for the component in the following order:
  • node itself
  • node reference
  • node's children
  • children of node's children

Arguments

  • const NodePtr & node - Node, whose hierarchy is to be checked for the specified type of component.
  • bool enabled_only - Enabled flag: true to get enabled component only, false to get component in any case.

Return value

Pointer to the component if any; otherwise, nullptr.

template <C class>

void getComponentsInChildren ( const NodePtr & node, Vector<C *> & out_components, int clear_vector ) #

Searches for all components of the specified type down the hierarchy of the specified node and puts them to the given buffer vector.

Arguments

  • const NodePtr & node - Node, whose hierarchy is to be checked.
  • Vector<C *> & out_components - Buffer vector, to which all found components of the specified type will be added.
  • int clear_vector - Flag indicating whether the buffer vector is to be cleared before adding the found components to it or not. Use 1 to clear the vector, 0 - to append new found components to the end of the vector. The default value is 1.

template <C class>

C * getComponentInParent ( const NodePtr & node, bool enabled_only = false ) #

Returns the first component of the specified type found among all predecessors and posessors of the specified node.

Arguments

  • const NodePtr & node - Node, whose hierarchy is to be checked.
  • bool enabled_only - Enabled flag: true to get enabled component only, false to get component in any case.

Return value

Pointer to the component if any; otherwise, nullptr.

template <C class>

void getComponentsInParent ( const NodePtr & node, Vector<C *> & out_components, int clear_vector ) #

Searches for all components of the specified type up the hierarchy of the specified node and puts them to the given buffer vector.

Arguments

  • const NodePtr & node - Node, whose hierarchy is to be checked.
  • Vector<C *> & out_components - Buffer vector, to which all found components of the specified type will be added.
  • int clear_vector - Flag indicating whether the buffer vector is to be cleared before adding the found components to it or not. Use 1 to clear the vector, 0 - to append new found components to the end of the vector. The default value is 1.

template <C class>

C * getComponentInWorld ( bool enabled_only = false ) #

Returns the first component of this type found in the current world.

Arguments

  • bool enabled_only - Enabled flag: true to get enabled component only, false to get component in any case.

Return value

Pointer to the component if any; otherwise, nullptr.

template <C class>

void getComponentsInWorld ( Vector<C *> & out_components, bool enabled_only = false ) #

Searches for all components of the specified type in the current world and puts them to the given buffer vector.

Arguments

  • Vector<C *> & out_components - Buffer vector, to which all found components of the specified type will be added.
  • bool enabled_only - Enabled flag: true to get only enabled components, false to get all components.

template <C class>

int removeComponent ( const NodePtr & node ) #

Removes the component from the specified node.
Source code (C++)
// removes a user component MyComponent from the node
ComponentSystem::get()->removeComponent<MyComponent>(some_node);

Arguments

  • const NodePtr & node - Node, from which the component is to be removed.

Return value

1 if the component was successfully removed from the specified node; otherwise 0.

void setWarningLevel ( int level ) #

Sets the warning level for C++ Component System. Warnings can be very useful when debugging your application, e.g. to investigate Null Reference Exception cases.

Arguments

  • int level - New warning level to be set. One of the following values:
    • WARNING_LEVEL::NONE - warning messages are disabled.
    • WARNING_LEVEL::LOW - warning messages are generated only for serious cases.
    • WARNING_LEVEL::HIGH - warning messages are generated for all cases including potential ones. At this level, for example, all Node/Property/Material parameters, that are empty at startup, will be reported.

int getWarningLevel ( ) #

Returns the current warning level for C++ Component System. Warnings can be very useful when debugging your application, e.g. to investigate Null Reference Exception cases.

Return value

Current warning level. One of the following values:
  • WARNING_LEVEL::NONE - warning messages are disabled.
  • WARNING_LEVEL::LOW - warning messages are generated only for serious cases.
  • WARNING_LEVEL::HIGH - warning messages are generated for all cases including potential ones. At this level, for example, all Node/Property/Material parameters, that are empty at startup, will be reported.
Last update: 2023-12-19
Build: ()