- Home /
How to set GameObject's component to an instance of an object
I have a few GameObjects set up to represent all of the player's controllable characters. Each controllable character has an RuntimeAnimator and a PlayerCharacter (custom class which holds a character's stats, growth rates, inventory, location, etc). I need to be able to set up the PlayerCharacter component at runtime given an already existing PlayerCharacter object in the code.
I am able to set up the PlayerCharacter component by copying each attribute over using GetComponent, but I will have to be constantly updating over 30 attributes because these change as the scene progresses. With over 20 playable characters in some scenes, it's horribly inefficient to be making deep copies of these characters and updating them after every action. Is there any way I can set these PlayerCharacter components to the instance that I have available in the code?
Your answer
Follow this Question
Related Questions
inspector,Component 0 Answers
PlayerPrefs on gameObject 1 Answer
Opening and closing drawers with start and end points 1 Answer