Skip to content

Example: Writing a New Component

jsutlive edited this page May 2, 2023 · 8 revisions

Writing new components is a simple way to add new behaviors to the system that can be exposed to the GUI. No UI changes are necessary to incorporate new components. Make sure the Component is in the root folder of the "Component" subdirectory in the source code. In order to add your new component via GUI, make sure to update the UserComponets.csv file located in the "Assets" directory of the project.

Inheriting from the base class

To start, first make sure to inherit from the Component base class. A template has been provided as part of this repository. To use it, select "Component (Cell Mechanics Simulator)" when writing a new script. You can also inherit from another component subclass, such as Mesh or Force.

package Component;

public class MyNewComponent extends Component{

}

Using the awake method to set an initial value for a variable

The awake method is called when the instance of the behavior is created. If we want to set a default parameter, we can do so here. This method will not be called again.

package Component;

public class MyNewComponent extends Component{
     int foo;
     
     @Override
     public void awake(){
          foo = 5;
     }
}
Clone this wiki locally