0
Answered

Add Component Action

Crispy 2 weeks ago in Game Creator updated by Marti (Lead Developer) 2 weeks ago 3

I managed to add Unity components by replacing the .Light, but how do I add my own components at run-time?

Unity version:
Game Creator version:
1.0.4

Answer

Answer
Answered

You can use the "Add Component" action, which works for both Unity and custom components. You just need to write down the name of the component and it will be searched and added to the targeted game object.

Answer
Answered

You can use the "Add Component" action, which works for both Unity and custom components. You just need to write down the name of the component and it will be searched and added to the targeted game object.

Entering only the name of the script did not work. Do I need to include a namespace? By default, it says "UnityEngine.Light, UnityEngine" which confuses me. This action could use a bit more explanation in the docs.

Yes, it needs to include the namespace and the name of the component. This is a bit confusing, as it needs to talk to the engine and make use of reflection. The nomenclature is "[Namespace].[Component], [Namespace]". However, I think that for custom components (the ones you create from script), using the name of it should suffice.