If I have two gameObjects, A and B, is there any way to take all the components from A and add them to B with matching values?
For example say there’s a BoxCollider on A as well as a couple random scripts with some variables. I want to take the box collider and all the random scripts and put them onto gameObject B. I don’t care what happens to gameObject A.
If you wanna pay 5 bucks, there is something on the asset store: Component Copier | Utilities Tools | Unity Asset Store Would be a time saving option.
Does this work at runtime?
You should be able to just call GameObject.GetComponent on B, Copy the variables you want via function call and if the component of the type you want doesn’t exist on A then call GameObject.AddComponent for A and pass the data from A to B for that component type. Repeat for all the component types you want.