I have two scripts and I want to pass a dictionary from the first to the second one:
CollisionController (Fill the dictionary)
DataController (Read the dictionary)
In the first, I fill a dictionary in OnTriggerMethod, and on Update, I validate that it is filled properly; the prints are shown properly. On the second (DataController) I create an instance of the script but on Update, I don’t see any values on the debugger. It’s like it is empty. Any ideas why is this happening?
Now let this code run. You may want to press “pause” in order to examine your game at runtime without having anything changing. When you now click on one of our debug messages in the console, Unity will highlight the context object that we passed along to the Debug.Log call. This should help identifying the objects involved.
That’s not “a thing” specifically in Unity. OOP is pretty pointless if you don’t know what objects you’re working with
how many collision controllers do you have on your scene?
you are probably dragging one that does not have the dictionary filled
( also as a bonus try making everything public instead of private to make sure some access limitations are not blocking you, after you have it fixed you can switch the things you need back to private. )
After some tests, I understand that the dictionaries that are getting filled in OntriggerEnter of the CollisionControler cannot be used from the DataController script. I filled a list in Start method and the DataController reads it properly. When I filled it in OnTriggerEnter I could not access it.
I figured out another way and it worked. I attached the script to an empty object and I use this only for filling the dictionaries. The other script was attached to many objects so maybe it was causing issues.