I make something and it works, and i dont know why it works

I ever touch unity and learn a bit about prefabs.

I try once again using prefab by dragging it into the project panel (is it the right name? is this the right method to make prefab?)

then I try to drag it into a button
image
and it works. and I do know why?

the main question is.

  1. when I try to delete the prefab the Scene loader from “Hierarchy” also gone and turns red so I need to make it again, why it happen?
  2. what should I do if i want to remove it from the project panel but still work on the “hierarchy” panel?
  3. when I remove I can’t undo (ctrl+z) what should I do if accidentally remove it? remake again?
  4. why my method works?

Addtional

I try to pause the video and do the challenge,
1, make a prefab
2. I make 2 scripts. :slight_smile:
image
3. I make “Load Start Scene”.
image

a. am I do the right method?
b. but it does the same result I wanted.

I guess I ask too much. :smiley:

Hi,

It’s great to see that you are exploring Unity yourself. This will help you gain a deeper understanding of this game engine. :slight_smile:

Regarding your questions, it is possible to assign a prefab or a game object to the OnClick field as Unity creates objects automatically. For instance, there will be a SceneLoader object. If you just assign the SceneLoader script, Unity will not create an object. For this reason, you cannot access a method inside the “script”.

In this case, you may assign a prefab to the OnClick field because the LoadNextScene method does not depend on anything in the scene.

Do you mean you accidentally deleted a file in your Assets folder? If so, check the Windows recycle bin. Usually, the deleted file can be found and retrieved there.

Regarding the “Additional” part, it looks as if you know what you are doing. For this reason, I would suggest to simply test what you did. In many cases, there are multiple ways to make something work in Unity. If your approach works, it’s a solution by definition. :slight_smile:

I hope this helped.


See also:

1 Like

Hi, Nina Thank you for replying so fast.

for recycle bin, yes I already found it <-- solved :slight_smile:

about the next one, about prefab.

  1. Am I use the right method? (by dragging it into panel) if not what are right method to make prefab?
  2. When I create empty what is it called? game object?
  3. When I create a prefab, how I make it part of the game object on “Hierachy”? I mean even i delete from asset it won’t damage “Hierarchy panel”?

image

  1. Am I use the right method? (by dragging it into panel) if not what are right method to make prefab?

Dragging a game object from your Hierarchy into your Assets folder creates a new prefab.

  1. When I create empty what is it called? game object?

If you create a new game object in the Hierarchy, it’s called a game object. It does not matter if it’s “empty”.

  1. When I create a prefab, how I make it part of the game object on “Hierachy”? I mean even i delete from asset it won’t damage “Hierarchy panel”?

Unfortunately, you can’t. At least, there is no option in Unity. You could reconnect game objects via code but that’s rather complicated and time-consuming. If you prefer to do that instead of simply dragging and dropping the prefab into your Hierarchy, look for scripts online.

The name of the game object in your Hierarchy is read. This indicates that the prefab might be missing. In past versions of Unity, if you deleted the prefab, the game objects linked to that prefab broke. Maybe that was changed. If you retrieved the prefab, simply delete this game object in the Hierarchy and drag and drop your “Scene Loader” prefab into the Hierarchy.

Is there any other way? or what I do is already the right one?


for tidiness should I make another folder called prefabs and save all prefab there?
or should put them in the scenes folder?


There’s no other way to do that unless you add third-party add-ons. So yes, draggin and dropping is fine. Here’s the documentation if you want to take a look.

Sure, you can create a new folder and add all your prefabs there. How you organize your projects comes down to preference and the needs of the project. Just a small warning, be sure that your prefabs aren’t nested in more than 2 folders, prefabs are things you’ll use a lot, so having to click many times to reach an object can be… obnoxious.

Thank you so much,
I found this forum really helpful.
since I start I really have difficulty understanding the idea.

I might redo some parts, and more active in this forum.

anyway, I am not too good with doc.
I might ask to help me to find the right paragraph or line or syntax which helps me.

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

Privacy & Terms