Pro's and Con's of adding ObjectHit script to parent folder

I JUST started the video and received the challenge to create ObjectHit script and then add the script to each of the 4 walls.

// this is my first ever programming series and I LOVE THIS!

Well since the start of this series, I have been putting everything into parent folders. I.E. So my player object named ‘Poggers’ is in a parent folder ‘Player’. I also have a ‘GameBoard’ parent folder which houses the ‘Plane’ object and then at that same level ‘Walls’ which houses all 4 ‘Wall#’ sides. So I am messing around and realize I can add the ObjectHit script to the parent folder Walls and I don’t see it directly on each of the ‘Wall’ Ojects [Wall0, Wall1, Wall2, Wall3].

I am curious to whether or not anyone does something like this to mass control multiple objects or is it a horrible illadvised practice. Hell, it may not even work, and even worse I am going to feel dumb if he talks about this in the course.

I am going to break from the course and do it my way and see if it works, but in the end if he doesn’t talk about it I will undo the attachment to the parent folder and attach it individually.

To my noob brain it just seems like doing it once is easier and more efficient than manually attaching it to 4 places. Obviously if we wanted one wall to behave differently than my reasoning is invalid, but anyway. Just curious.

Thanks for reading.

Hi Allen,

I’m not sure if I understood you correctly. What do you mean by folder? A folder in your Assets folder? I’m asking because you also mentioned “Wall” objects. Maybe you could share a few screenshots of what you mean to ensure we will refer to the same?

Nina,
Sure, my apologies, I have no idea to describe things yet. So per your request here you go:

Nina,

Well, I learned through trying. It does not attach the script to the individual objects when I try it my way. Also I learned I can’t drag the script onto a group of items , ie, highlight wall0->wall3 and drag the script onto them in the Hierarchy. That doesn’t attach it to them either. I had to drag it over to the inspector.

Anyway, next time I will wait and see if it works before I ask a question.

Thanks for the quick response.

Actually, when you select multiple game objects in your Hierarchy, you should be able to attach your script or a component to all of them at once by dragging and dopping the script onto the Inspector window. It might be that it was possible to drag and drop scripts onto multiple selected game objects in the Hierarchy in past versions of Unity. Since the Unity programmers change the behaviour from time to time, you’ll always have to test your ideas to figure things out. That doesn’t have to anything to do with being dumb. The opposite is the case.

The parent game object, in your case: Walls, does not act as a parent collider. The children need their own colliders. The meshes in Unity might look solid but they do not have any “physical” body in the scene. They are just looking good for the camera.

However, if you put a Rigidbody to the Walls game object, you could have a script with OnCollisionEnter on it, and that method would get called if something hits the collider of a child. The Rigidbody acts as a compound collider.

1 Like

Yes, I could attach the script to all of them dragging to the inspector screen, just like you say. But the version I am currently using doesn’t allow dragging onto a group in the hierarchy and ‘mass’ applying the script or component onto the hierarchy.

As for 'Walls" I was hoping it would act as a ‘parent folder’ and allow me to change or add or remove something from the whole group under it at once. I guess in actuality I was attempting to use it as a prefab, but alas, it doesn’t work. Prefabs, however, do seem to work wonderfully for that purpose.

I must say, this course is amazing! I have never had this much fun learning in my life, and I love learning!

I hope you folks keep finding material to produce more lessons because at this rate I will have gone through all the courses in a few months!

Thanks again for your help, I promise I will wait to ask questions until AFTER I complete the lecture and after I have done some testing. I was more of ‘thinking out loud’ because this is so exciting, learning and instantly seeing results.

It’s great to hear/read that you are enjoying the videos. Don’t hesitate to ask if you have any questions regarding the content of our courses. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms