How to use AttachToComponent

Some of the pointers used in this line is NULL, add checks before it to figure out which.