Prefab Reference or Prefab Instance Reference

In a previous tutorial Rick suggested dragging and dropping a particle system prefab instance from the hierarchy onto the inspector and cautioned against using the prefab from the project. However in this tutorial we are dragging and dropping the prefab from the project onto the inspector. Can anybody explain the difference in approach? Thank you.

Hi,

To which previous tutorial are you referring?

Hi Nina,

I created this post under the mentioned tutorial but somehow it did not appear there.
This tutorial refers to: Argon Assault > Instantiate At Runtime.
And previous tutorials refer to anything that comes before this.
In this tutorial we are adding a particle system to the enemy objects and in previous tutorials we added a particle system to the player. When adding the particle system to the player, we used the prefab instance and when adding the particle system to the enemies we used the prefab.

I see. I asked because we have multiple courses, and this course was recently remastered by Rick. So there was a chance that you referred to something else, maybe the archived videos.

A prefab is a game object in the Assets folder. It is not in the scene. We usually assign a prefab to a variable in the Inspector to be able to spawn copies of that prefab during runtime. This could make sense if we, for example, wanted to display special effects after the enemy dies (and the Enemy game object got destroyed). Particle Systems cannot be played on destroyed (= non-existent) game objects.

Is this what you wanted to know?

Hi Nina,

Thanks a lot for your help. That was not what I wanted to know. It’s a little hard to explain with words so I will refer to the tutorials.
In Argon Assault > Trigger Player Explosion > 2.38 min, Ricks says not to grab the prefab from the asset directory. However, in the next tutorial, Instantiate at Runtime > 4.32 min, Rick grabs the prefab from the asset directory. So I wanted to ask when you should use the prefab instance (from the hierarchy) and when you should the prefab (from the asset directory). Hope this made the question clearer. Thanks.

Never. There is no prefab in the Hierarchy as prefabs cannot exist in the scene. Prefabs only exist in the Assets folder. For this reason, it is impossible to use a prefab from the Hierarchy. If you meant a game object, you want to reference it if you need to access it. For example: If your space ship has got guns and you want to activate/deactivate these guns during runtime, you need to reference the guns of your space ship, not “some” guns that don’t exist in your scene.

And we reference prefabs if we want to create duplicates based on a blueprint (= prefab) during runtime, e.g. enemies that get spawned during runtime. Or bullet game objects that are supposed to get spawned during runtime. We do not want to reference a game object from our Hierarchy in this case because that game object could get destroyed during runtime, and that would break our game.

You made the situation very clear. Thanks a lot for your help Nina.

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

Privacy & Terms