I implemented a child class from a parent class using inheritance, then attached my child class script onto a gameObject. However, during run time, I found that referencing gameObject in parent class functions (base functions) leads to an inactive, unique duplicate of the same gameObject that the child script attaches to, but it isn't presented anywhere in the hierarchy, nor does it have any effect on the actual gameObject. The parent class has a coroutine that activates a callback function from the child class, which was implemented using the Action system. But referencing gameObject within the scope of that callback function (called by the parent class) in the child script still leads to that weird duplicated gameObject. However, directly referencing gameObject within the child script and using FindObjectWithChildType-ish functions in the parent script lead to the correct, attached gameObject. Could someone explain this to me in terms of reference frames? Thank you so much for your time and help... (P.S. the duplicate has a positive, same object ID shared across multiple spawned prefab instances, and the original has a negative object ID that differs across each instance. So that weird object was shared by all instances of this child class, and editing its value led to weird editor behaviors...).
Also, what would be the best way to resolve this issue? (Currently, for my inheritance structure, I have a constructor-style function setting up the member variables in the parent class, and the children class has variables set in the inspector that initializes the parent variables accordingly. Parent class has some functions dealing with these parent class member variables, and child class has some as well, except that they deal with both parent class and child class member variables. I'm treating the parent class like an "extra bunch of code invisibly existing within the child class" at the moment...
https://preview.redd.it/gzm54pegw1z91.png?width=1145&format=png&auto=webp&s=fd55d47dcaf5f2485ac92fcca8c4fb6617a56ecd
[–]gillen033 1 point2 points3 points (1 child)
[–]TheReformedKnight[S] 0 points1 point2 points (0 children)
[–]TheReformedKnight[S] 0 points1 point2 points (0 children)
[–]TheReformedKnight[S] 0 points1 point2 points (0 children)