Cant drag global gameObject into new unity nested prefab system - unity3d

Im just starting to use the new Unity nested prefab workflow (or what ever you call it) in Unity 2018.3
So how it works is when you want to edit a prefab, you select it then click on the arrow. When you do this it erases everything from the hierarchy window and then you only have that prefab visible until your done editing it, you click save and then its back to the original hierarchy that was there before you started editing.
This is all fine, but the problem is what if i want to drag a game object from my scene into the prefab im editing is now impossible because as soon as you start editing the prefab, it removes your scene and only shows the contents of the prefab. So you cant drag anything from your scene into the prefab any more because its gone for the duration of the editing.
I dont know if im making myself clear or not.... But basically im saying while editing the prefab, only the contents of the prefab is visible, your scene is not visible, so you cant drag any object from your scene into the prefab anymore.
Anybody knows how to get around this? Right now i want to drag a gameObject from my scene into a prefab im editing to make a reference to a global object, but while editing the prefab my scene is not visible, so i cant do it.
Thank

Just create a copy of your prefab in Hierarchy and make you required changes to that copy once done, drag and drop that copy on you prefab and it will be updated.
When dropping the copy on your prefab you can either create a new prefab or update the original one.

Editing a prefab can be done in multiple ways. To achieve what you want, you should drag an instance of the prefab into your scene where your "other" gameobject is. Ensure that the prefab instance is blue, so that you know that it is still connected to the prefab.
Now, drag your "other" gameobject onto the prefab instance, so that it becomes a child of it. Now you should be able to apply prefab changes through the inspector.
Do note, if you cannot change the position in the hierarchy of the "other" gameobject onto a prefab from within the scene view. If you want to change the position, you should open the prefab scene after applying changes.

Related

Reassign prefab in Unity

Is it possible to reassign a prefab to a GameObject? I removed a prefab because the prefab attached script was removed and was throwing a warning. I was unable to remove the script from the inspector and save it, so I had to remove the prefab.
If they are made from the same prefab, what you can do is: Drag one object from hierarchy to "Project" as you would create a new prefab from the existing "missing" prefab.
This would ensure that they have a new parent prefab - with the same GUID as previously.
One downside would be that it revert the names of all prefabs in the scene you are currently in, to the new prefab name.
NOTE: This would not work if you closed the scene or Unity.
EDIT:
You can also modify scene manually by assigning m_PrefabInstance: {fileID: 665558973} to the same ID for all your GameObjects. GameObjects with missing prefab would have fileID: 0.
You need to do this for all components probably (GameObject, Transform, Components etc). Make sure you have backup before trying this though.

how to change hierarchy on prefabs

I am new to unity and working on a image viewer in unity2D.
I am not sure if I choose components true but for now working fine.
most of the project is script based
I created a prefab which has a raw image
and in script I Instantiate prefabs in a scrollviews content
images are displayed no problem in that
I added some events where I Instantiate my prefab pointerDown, beginDrag, endDrag
dragging workin fine too
but when I drag any added prefab to older added prefab it stays on top but if I drag it to a newer added prefabs it stays under them.
I think its because the hierarchy order.
how can I change the order or how can I manage to make prefab stay on top when dragging
ps: on the image thumb_0 is added first and after drag it stays on behind thumb_2
if you can access the Transform of your prefabs you can use the method SetAsLastSibling(); it will move your gameobject to the last spot under your parent object, therefore causing it to be drawn on top
https://docs.unity3d.com/ScriptReference/Transform.SetAsLastSibling.html
EDIT :unless you mean dragging it manually, so then drag it to the bottom , last item always appears on top

Unity deforms every prefab that I create

I have problem with Unity prefabs. Every time I create a nice looking UI in main scene and I want to store it as prefab for later usage if I open this prefab it's deformed(random cliping, moved UI elements in different directions, ... such a mess). If I try to fix this prefab in prefab editor to make it nice looking like before and then if I insert this back to scene it's totally unusable. It creates bigger mess than before in prefab editor... I don't know what to do. Editor throws no errors btw.
In first image is nice looking UI(example already created). In 2nd image is prefab editor. Text is totally out of panel and 3rd is from back in scene (means removed old one UI and place stored prefab from folder) the panel is gone.
Imgur - images are orded by scene to prefab editor and back to scene
On those images you can see a 3 elements... but if I make more complex UI, it's clipping through each other in prefab editor and also back in scene.
Unity version: 2019.1.7f1

How can you make a prefab that can expand to show its constituent objects?

I am very new to Unity3d. I want to make an prefab that expands with a little right facing button to show other objects. I have tried giving the prefab children and then dragging it into the project window, but it didn't show the little right-facing arrow. Can anybody help?
To add components to a prefab, add it to the scene as you said you have, then drag your next object on top of the prefab in the Hierarchy window. Sometimes this places it relative to the prefab but does not actually child it, so simply drag the object now in your Hierarchy onto your prefab once more and it should fall in place as a child, you will know this worked if you now have an expand node next to your prefab.
First, make your root game object that you will convert into a prefab.
In order to add objects which are children, right click on the root object and then make the children. You can also drag other gameobjects onto the root game object to make them children of the root game object.
Finally, drag your final prefab into window where all of your files are, and the resulting prefab will have children.
If you want to change the prefab after it is made, you have to change one object that results from your prefab and after changing it, click Apply in the top of the Inspector window to apply that change to all other objects resulting from the same prefab.

Why isn't Unity allowing me to apply certain changes to a prefab?

I have a prefab called square in the asset tray, I drag it into the scene to create an instance of the square prefab (in the hierarchy it is highlighted blue and has the select, revert and apply buttons in the properties). If I move/resize the instance and then press apply, the changes are applied to the prefab.
However, the square prefab has a script with a public game object. I drag the game object from the hierarchy into the slot in the instance's properties tab and is shows that the script is now referencing the actual gameobject. However, when I press apply this change isn't applied to the prefab (the prefab's script still isn't referencing any actual gameobject). All other changes to the prefab are applied.
I have tried dragging the instance into the asset tray to create a new prefab with the changes, but, as soon as I do, the script no longer references the game object.
I shouldn't have to create an entirely new prefab every time I add a public variable to a script so why can't I apply this change?
Ok you can't really drag an instance to a prefab. As a rule of thumb keep instances with instances and prefabs with prefabs.
I would instead find the instance from the prefab when this one is instantiated, with a method like findobjectoftype, or gameobject.find. Let me know if you want me to expand the answer
Solved: Prefabs can only reference other prefabs since there might not be an instance. Made the actual gameobject into an instance of a prefab and applied the prefab to the script
Prefabs are Assets. You can reference only other Assets to an Asset, never instances of Assets.