- Home /
Get instance of exisiting object
I've looked for a while now, and I can't figure out how I can get an instance of an object (a c# object!, not unity gameObject!) from another script. As an example I have a class like this:
 public class GameManager : MonoBehaviour
 {
     public Dictionary<string, Object> myDictionary = new Dictionary<string, Object>();
 }
And I want to be able to get that dictionary from another class. The class that I want to use the dictionary on doesn't derive from MonoBehaviour. I thought that adding a simple "get" method for the myDictionary inside the GameManager would allow me to access it across other scripts, but nope. This whole MonoBehaviour class is a bit confusing to me... I could simply create a new instance to get the dictionary but that would also create a new dictionary... which isn't what I want.
IE: Use a method in the GameManager class I created which derives from MonoBehaviour to get the myDictionary on a class that doesn't derive MonoBehaviour.
Answer by Waverunn0r · Oct 14, 2013 at 08:37 PM
 GameManager gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
Wonder if this is my solution?
Yep, that was my answer. I am going to make a helper class now for all of the $$anonymous$$i-manager objects that I have now that I know what to do...
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                