#Problem with a GetComponent

10 messages · Page 1 of 1 (latest)

chilly hazel
#

Hi, i was trying to access to a methodle that is in the parent of an object so i tried to: "itemInTheSlot.transform.parent.GetComponent<InventorySlot>().WhoIsChildUpdate;" were itemInTheSlot is the child. I was trying to access to the method "WhoIsChildUpdate" of the script "InventorySlot" that is attached to the parent of "itemInTheSlot". Do you know why it is an error?

#

the error says: Only assign, call, increment, decrement, wait, and new object expressions can be used as statements

strange citrus
#

You're missing the parentheses after the method name.

chilly hazel
#

🤦‍♂️

#

i treated it like a variable

strange citrus
#

If you want to call a method, you always need to end with (), otherwise you're accessing the method declaration instead.
Sometimes this is what you want, but normally not.

coral grail
#

Lend me your brain when it's idle 😁

chilly hazel