C
C#•2y ago
eimiieee

Accessing a table in a list of subclasses (unity)

Hello, i'm trying to change a value of a table during runtime. I have a unity object called manager that is the main, which in turn contains a class called unit, unit contains a list with costumes, along with all the options in a table, where of inside there is a simple bool which i'd like to change from ALLOWED to DISABLED and vice versa, however when i try to access this during runtime it tells me that the object I try access doesn't exit even if i know it's there and, simplified it's something like this
var example = Manager.unit.costumeMap[0];
example.costumeTable.usingType = Manager.costumeTable.USING_TYPE.ALLOWED;
var example = Manager.unit.costumeMap[0];
example.costumeTable.usingType = Manager.costumeTable.USING_TYPE.ALLOWED;
What I doing wrong?
6 Replies
hiyosilver
hiyosilver•2y ago
Really hard to say without seeing the actual code, but if it's telling you some object doesn't exist, I'd wager you are mistaken in thinking that it does 😄 Have you tried setting a breakpoint and checking the values at each step? Apparently something isn't properly initialized when you think it should be.
Anton
Anton•2y ago
some object in the chain must be null you have to check for nulls how you check that depends on whether it's a unity object or a simple object
eimiieee
eimiieeeOP•2y ago
What's the difference between checking them for nulls?
Angius
Angius•2y ago
Unity overloads null in some weird ways Where x == null might be true, but x is null might be false
Anton
Anton•2y ago
x == null checks if x has been destroyed, or isn't assigned
eimiieee
eimiieeeOP•2y ago
Thanks so much I will see if doing those checks helps me
Want results from more Discord servers?
Add your server