#How to save GameObject selection through Prefabs.

1 messages · Page 1 of 1 (latest)

queen trout
#

I'm a little confused as to how I can save a selection (the "[SerializeField] private" for gameobjects) through prefabs. I tried changing the selection to 'public' and it didn't work.

the code is for the movement of my enemies in-game. I followed this tutorial:

https://youtu.be/2SXa10ILJms?si=KnNmbxtAXFRGMJgo

Like and subscribe for more ai video

Main Channel: https://www.youtube.com/c/bblakeyyy

Patreon with fully explained c# scripts:
https://www.patreon.com/BlakeyGames

NEW SERVER LINK: https://discord.gg/cyskvvyDeH

Silhouette Dash free download:
https://blakey-games.itch.io/silhouette-dash

Join the discord community!:
https://discord.gg/3CTfX...

▶ Play video
atomic carbon
#

can you be more specific about what exactly you are referring to?

queen trout
atomic carbon
#

prefabs cannot reference in-scene objects. so the prefab doesn't have a reference to the player which is why there is no reference assigned when you add the prefab to the scene.
you'll need to pass the reference at runtime when you instantiate the objects, assuming they are instantiated and not just in the scene already. if they are just going to be in the scene already then just copy/paste one from the scene so you don't have to set up the reference on each one

how to pass the reference at runtime: https://unity.huh.how/references/prefabs-referencing-components