Questions tagged [prefab]

92 questions
2
votes
1 answer

How do I change a Unity prefab's sprite after instantiating it based on the data I input?

For context, I don't have much Unity and C# experience, so please don't berate me if the answer is really simple. I'm trying to make a dungeon's edge tiles automatically create walls on their respective edges (e.g. the rightmost column of tiles has…
2Mult
  • 25
  • 5
2
votes
1 answer

How to get a reference to a prefab asset in unity

I have the following class using System.Collections; using System.Collections.Generic; using UnityEngine; public class PixelSystem { public GameObject pixelPrefab; public Texture2D[] style; public…
Jacob
  • 135
  • 2
  • 12
2
votes
2 answers

Attaching prefab's script to another prefab as a component

I have Player prefab with script Player Also I have GameController prefab with script TouchMove. This is TouchMove code: public class TouchMove{ [SerializeField] Player player; ..... } So TouchMove has player object as a component, which I…
2
votes
1 answer

Setting a prefab as child of another game object in unity

public GameObject aiArrow; aiArrow.transform.parent = this.gameObject.transform; When I try to set up a prefab as a child of another object the following error occurs. Setting the parent of a transform which resides in a Prefab Asset is disabled…
Savad
  • 1,240
  • 3
  • 21
  • 50
2
votes
1 answer

Should I include the Canvas parent GameObject in a UI prefab in Unity

I have four different Canvas elements in my Unity scene. This organizes them by concern, but also improves performance since I don't have to rebuild all the elements if I "dirty" one of them. I want to create prefabs of each so I can reuse them…
ow3n
  • 5,974
  • 4
  • 53
  • 51
1
vote
1 answer

Unity - getting the correct text size after Content Size Fitter

Please help, I can’t figure it out myself I have a TextMeshPro Prefab I wanted the height of the object to match the actual height of the text, so I added a Content Size Fitter component to the prefab and gave it a Vertical Fit - Preferred Size. In…
KOSOY
  • 21
  • 3
1
vote
0 answers

How do I delete GameObjects in a prefab variant? (EditorCode)

I am currently working on a room editor. The room is a base prefab with scripts. It has a child transform with tiles, which is empty. In my editor, I instantiate a base prefab room, and design whatever tiles should be in it, and save it as a prefab…
Ava
  • 502
  • 1
  • 6
  • 21
1
vote
0 answers

A Enemy Prefab with two different hitboxes both detect and take damage from bullets in unity

I made a enemy prefab and a object to it (Field of View). The enemy has a Box Collider 2D and a Rigidbody 2D, the FOV only has Box Collider 2D. The enemy checks if a bullet is hitting him and takes damage from the bullets. My problem is that he gets…
CodingGuy
  • 11
  • 3
1
vote
1 answer

I can't drag gameObject into prefab public variable

I have a bullet prefab in 2D unity and I want to drag a gameObject into a public variable so I can deal damage but it won't work. Here is my code, the gameObject I want to drag in is called EnemyAI and there is a script called EnemyAI. public…
1
vote
1 answer

Dependencies between Android native modules (prefab) fail to build

Our Android application consists of 40-some Android Library Modules (ALMs), each of which also builds a C++ shared library with externalNativeBuild and CMake. So far we had the dependencies between these libs set up like this: The dependent ALM…
marczellm
  • 1,224
  • 2
  • 18
  • 42
1
vote
1 answer

Unity Add callbacks to prefab objects dynamically in code

I am creating a canvas with a table containing TextmeshPro Input fields on a row. I'm using the XR Input System for the Oculus Quest Vr Headset and wish to handle input from the controllers so they can interact with the Input fields (Select and…
Mark
  • 166
  • 1
  • 13
1
vote
3 answers

How to reference camera in prefab script in Unity 2D?

I have created a player prefab (called Tim in my project) and am trying to make all the references to gameObjects and transforms directly from the one of the players scripts which is actually attached to a gun object which is a child of the player…
SKYZE
  • 59
  • 1
  • 9
1
vote
0 answers

Layer or hierarchy problem for GameObject

In my Unity project, I made a prefab to rendering images from web sources by URL. However, when testing the app, it displayed the images like this: There are two image windows, but you can see, the image in the first opened window is floating over…
Chenchen
  • 35
  • 6
1
vote
0 answers

Prefabs not visible in unity scene

I bought an asset from unity store and installed XR interaction toolkit therein. Everything works fine. When I drag prefabs from another asset into the scene and deploy it into oculus quest 2, these prefabs become invisible. I have tried giving…
Craving_gold
  • 189
  • 1
  • 14
1
vote
1 answer

Unity Prefabs missing after pulling project from GitHub

I started to make a project on a Windows computer and uploaded it via GitHub. Later I wanted to download it on my Mac. But when I start the project on MacOS Unity the scene is empty and all prefabs are missing. Every time when I check GitHub it is…
1
2 3 4 5 6 7