RequireComponent (typeof) not adding in component
Hey guys, correct me if I'm wrong, but the RequireComponent is suppose to add the required component at runtime right?
Here is my script
I've done this in the past and it worked, but I just recently upgraded to 5.3, and it doesn't seem to be adding the Rigidbody2D component. I compare the codes to my previous one and it seem just about right, am I missing something else?
It still does for me. try to remove and add the script again
Oh yeah, that seem to work, but seems kinda unorthodox and unintuitive that you have to remove and re add the script.
Indeed. It would be good if at least it complained of the lack of component (like an assert).
Answer by okletshavesomefun · Sep 04, 2016 at 01:22 PM
@Positive7 @Chng Ugh this solved it for me too, which made me realise what the documentation for RequireComponent means with this: "Note that RequireComponent only checks for missing dependencies during the moment the component is added to a GameObject. Existing instances of the component whose GameObject lacks the new dependencies will not have those dependencies automatically added."
Answer by mani3307 · Mar 16, 2018 at 12:11 PM
Simply Saying, Create The script separately in the project window, after Completing the script, add it to the GameObject then it works