# Add Components at runtime

The asset wasn’t really designed with AddComponent in mind. Adding a SpringComponent in the Inspector, setting it up and optionally referencing it from some other script is always the ideal recommended use case.

**But if, for some reason, you want or need to add a SpringComponent at runtime this is how you do it:**

1. Add a SpringComponent in runtime
2. Setup the SpringComponent
3. Initialize the SpringComponent
4. Use it normally

**Here 2 examples:**

```
colorSpring = gameObject.AddComponent<ColorSpringComponent>();
colorSpring.SetAutoUpdateToTrue(isRenderer: false, uiImage.gameObject);
colorSpring.Initialize();
colorSpring.SetCurrentValue(Color.white);
colorSpring.SetTarget(Color.yellow);

```

**And:**

```
transformSpringComponent = uiImage.gameObject.AddComponent<TransformSpringComponent>();
transformSpringComponent.useTransformAsTarget = true;
transformSpringComponent.followerTransform = uiImage.transform;
transformSpringComponent.targetTransform = uiImageTarget.transform;
transformSpringComponent.SpringScaleEnabled = false;
transformSpringComponent.Initialize();

```

**You can find the full example from above in:**

Assets\AllIn1SpringsToolkit\Demo\Scripts\ExampleAddComponent.cs


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seasidestudios.gitbook.io/seaside-studios/springs-toolkit/add-components-at-runtime.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
