Questions tagged [prefab]
92 questions
0
votes
0 answers
How to duplicate, reuse, and dispose of dynamically generated addressable objects
How do I load an addressable AssetReference dynamically, like a crate or something, via LoadAssetAsync and then reuse it throughout my game without calling LoadAssetAsync again?
I am generating a series of square platforms that are addressable…

jumpwire
- 101
- 1
- 9
0
votes
2 answers
Disable Child Element of a Prefab with Script
I have just started to learn Unity 2d and I have taken a task at hand where I want to Instantiate a Prefab from Assets folder and then disable some of the child elements in it once the prefab is initiated. Following is my code :
void…

Rerise Studios
- 5
- 2
0
votes
0 answers
Unity prefab corruptings/not saving info
basically from months when I open my project, it happens that some prefabs deletes all the reference from the scripts connected and I get all the errors from the console because the script can't find the references anymore, it's really strange…

Kevin99
- 35
- 1
- 5
0
votes
0 answers
OnMouseDown in prefab not working with some scene
I have prefab enemyRangeAttack and then I add this code for enemy (child of enemyRangeAttack)
public class Selectable : MonoBehaviour{
[HideInInspector] public GameObject Player;
public float range = 10f;
private void Awake()
{
Player =…

NgDat
- 15
- 7
0
votes
1 answer
Unity - find only top level objects of instantiated prefabs
I am developing an edit-time level editor.
I have an Apple prefab.
I also have an AppleTree prefab.
The AppleTree prefab has, as children, several Apple prefab instances.
Both prefabs have an attached script, called 'Prop'
I drag an AppleTree prefab…

Maxxx
- 3,575
- 1
- 19
- 18
0
votes
1 answer
How to activate and access GameObjects from inside a Prefab (with a button)
I am currently trying to build a shop for my game. The shop is a list, that will be displayed onscreen and consists of Prefabs that each have a button component. On click, a hidden panel should be visible and different UI elements should be…

Josh
- 17
- 3
0
votes
1 answer
What is the best way to create a prefab object in Unity with a randomly generated mesh?
I have been working my way through quill18's hex-based civ-style game coding tutorial for Unity. As I finish up the series, I'm trying my hand at generating random meshes rather than just using meshes imported from Blender. I've managed to write…

Andrej
- 1
- 1
0
votes
1 answer
How do I call another GameObject's possition in a Prefab Instantiated Gameobject's script?
If that is not possible, can I at least find it using raytracing?
I want to make some enemy GameObjects (which are instantiated from a prefab, which spawn randomly) always look towards the player.
I don't think I can just call it's xyz coordinates,…

Vladutzu27
- 55
- 9
0
votes
1 answer
How do I assign a method that is inside a prefab to the On Click() event on a button?
I have a button that is supposed to switch beetween light and dark mode in my game by running the method "ToggleTheme" inside the ObjectTheme script, which all the objects that I want to be affected by light/dark mode have. ToggleTheme just changes…

Jonatan Zelič
- 3
- 2
0
votes
0 answers
How to scale instantiated prefab objects in unity to fit different screen sizes
Hey i am wondering if there is a way in unity for you to scale prefab objects that is instantiated to be able to fit different screen sizes in unity so that no matter the device your game is downloaded on, the prefab too would scale.

Jerry
- 21
- 4
0
votes
2 answers
Is a good practice to create one prefab and one script per enemy type?
I'm in the process of creating the enemy for my tower defense game.
I want one enemy to be tanky (lots of health)
one enemy to be fast
one enemy to cast spells to boost other enemies
Based on my research, I could create an enemy base class, then…

Rokugatsu29
- 3
- 1
0
votes
1 answer
Unity Card Hover Animations
Hello everyone I am trying to make a hover animation to my cards. When you hover over cards in your hand I want them to go up but the card is a prefab so when I hover over one (or click on one) they all go up at the same time. This is a small…

bartugenccan
- 51
- 5
0
votes
1 answer
How can I get a reference of a prefab asset from the code in it self?
So let's say I have this prefab asset, "P" and have this code attached to it.
public GameObject selfReference;
[ContextMenu("GetReference")]
public void GetReference()
{
selfReference = gameObject;
}
Note that:
the 'reference finding' process…

Imry
- 23
- 6
0
votes
1 answer
How to disable Prefabs in Unity 2D?
Im working on an 2d local multiplayer platformer Game. In the game are obstacles (Spikes), when the player collides with them the player will die. I want the Players of the game to decide if they would like to enable or disable the Spikes (the link…

derStargast
- 1
- 1
0
votes
1 answer
Are imported model and its prefab coupled?
I import models from Blender into Unity, then make prefabs from them. But can't delete the original imported models without affecting prefabs.
This is the step by step discription:
I create a simple model in Blender. Just meshes, without textures,…

Alex34758
- 396
- 4
- 14