Fix: getComponent(SomeClass.getTypeName()) bug
getComponent(SomeClass.getTypeName()) seems to not be checking the numbers after the colon ":" in the getTypeName() string!
When the string is the same before the colon for multiple components on the same SceneObject, it can return the wrong component. Been running into this a couple times and it took a while to figure out what the issue was.
-
Thanks Max -- with the project I can at least describe what's happening for you, but I'll have to go to the team for ideas on how we might improve things.
What's happening is that the system sees them as two versions of the same Component -- likely because you created "Script3" via right click -> Duplicate. The system then sees these as two versions of the same, so it's like you did `UIButton.getTypeName()` with UIButton 1.0 and received an instance of UIButton 1.1. You can see the Component UID in the meta file for your scripts. Both Script1 and Script3 have:
> ComponentUid: 41ded320-cc7d-4b9f-9e13-3ab8a0332b75
It's definitely not helpful in this context and we'll think through how to improve things, but to mitigate impact you can either change the ComponentUid in the meta file or avoid "Duplicate" when creating new TS files.
-
Max van Leeuwen
commented
Here you go! This project retrieves the wrong thing from a sceneobject, using getComponent(thing.getTypeName())
(The colon might not be the problem but the identical typename before it does look suspicious)
https://drive.google.com/drive/folders/1sjHf9A2MdlrpIGbLP67t75Gza68nRozY?usp=sharing
-
Hey Max, can you provide an example? We took a look at both the runtime implementation and the TS compiler and don't see the issue you're highlighting.