I have a problem :
I create a project and add the game object (a robot) into this project.
When i add the component (this is a c# script) to my robot, a dialogbox show “Losing prefab-Adding a component will lose the prefab parent”.
what is problem? How can i do?
More information:
I add two GameObject : a Plane (Mainmenu / GameObject / Create Other / Plane) and my robot. When i add component (my c# script ) to the Plane, it’s OK, but when i add to my robot a dialogbox show “Losing prefab-Adding a component will lose the prefab parent”. and function void OnMouseOver(){} don’t run!
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnMouseOver()
{
print("OnMouseOver");
}
}
When Unity tells you that you are breaking a prefab connection it is just being polite, its not a problem.
The official method would be to import the robot asset, make a prefab from the Create menu in the project pane and name it “Robot”, drag the robot asset onto the empty prefab, then select the prefab and drag the script onto the inspector to attach it.
As for OnMouseOver not getting called, it is probably because the robot has no collider. It needs a collider.
And you can (after breaking the prefab connection) apply changes to the prefab as well as re-establish the prefab connection go to the GameObject menu and select the apply to prefab option.
My continued problem with this is that 95% of the time is looses the link to the original file. I’ve done as listed as well where I make a prefab first, then drop the model file (.mb) into the prefab, then put the prefab into the scene. But eventually I have to add something to it like collision or a script and after doing so if I need to update the model because of requested changes, then unless its moving some verts or UV I have to create the whole prefab again because the link between the model file and the prefab is destroyed. If I add extra geometry or delete geometry then the changes are reflected in the model file, but I have to re-drag that back onto the prefab to get the changes across, and usually that means they’ll go back to the origin as well and will need re-positioning in the scene.
Is nobody else seeing/having this problem as well, or am I also still doing something wrong? Again, I’ve tried 1) putting a model straight into the scene, 2) first creating a prefab and putting the model into that and then the prefab into the scene, and 3) creating 2 prefabs, putting the model into one and then that prefab into the second prefab, but any time I get “loosing connection/breaking prefab” I cannot get update changes to the model to propegate through to the scene. Just something for hungkv to be aware of as well unless there’s a fix to be had.
I know what you’re talking about with regard to models in prefabs becoming “frozen” in terms of their contents. It is the currently designed behavior, rather than a bug. There are pros and cons to it. The frustration is that there are times like yours when you need to update the model (and I’ve had plenty of those). The value is that the model in the prefab is stable, and so additions you’ve made, such as colliders or scripts, to the hierarchy of the model itself, are stable and won’t get messed up by reimporting the model. So it’s something of a double-edged sword.
If memory serves, this is a more general characteristic of prefabs added to prefabs, rather than just an issue with the models. And it is, in fact, by design, even though it creates these limitations.
There have been Wish List discussions for a type of prefab that would update all of its children in other prefabs, but we don’t have one yet.
Seems a weird way to have as the default considering it allows for building a model and making a prefab of it, changing the model and making a new prefab of it, and changing it again and creating a third prefab, thus resulting in 3 different ‘versions’ from one model file of which two you can never get back to and you’ll still need to re-attach any scripts and setups to your newest model/prefab to make it work like you’d set up the first. Perhaps a ‘simple’ “Propagate changes to scene/prefabs?” dialog or checkbox in the import options.
This is a terrible limitation in my opinion as that it forces you to either adhere to a strict production pipeline (finish model first, import to Unity, add components) or re-do the prefab creation process for each one.
It’s about 2 years have passed since the last post. Have anything changed in Unity 3.0 f5? Because I had a problem with “frozen geometry” yesterday, and I couldn’t find the answer for this (until I’ve found this topic).
I’ve imported a model and placed it to the scene. Then I added a mesh collider to one of it’s objects. Then I got “Losing prefab-Adding a component will lose the prefab parent” message. After that I had 2 hours of strange things happening in my project (with non applying changes).
To my knowledge and experience nothing has changed. If you create a prefab from a mesh then do something to the prefab that gives you the ‘Losing Prefab’ message, then any subsequent changes to the mesh as far as adding or deleting objects or verts/polys will require re-building the prefab again. I still don’t know why this is the way it was designed versus pointers to the objects that make up the prefab and it’s still wholly aggravating and frustrating to me, but something I still have to deal with too.
Just bumping this thread to say that having a solution for this would be great. We have a couple of prefabs with several large components with lots of data hookup (usually player related), and not being able to really tweak things like node placement after the fact is really putting a dampener on our workflow.
Has anybody found a good solution to this problem, other than, say, manually reconstructing everything via code?
What this makes even uglier is that you can not copy components from one object to another so that you actually have to do it all again. Maybe an editor script can help here?
One of the ways we’re currently kind of working around the problem (but not solving it) is by adding another layer of indirection. Instead of dragging a model into a prefab and attaching scripts to that parent object, we’re making the model a child of the base prefab. If the model gets out of sync it’s just a matter of deleting the child in the prefab and dragging a fresh one back in.
So your scripts that don’t reference things specifically in the model (like, say, sounds or variables in CharacterController or things like that). Don’t get touched. If you need to reference bones or things in the model itself you have to update the connections, but we find that the majority of the heavy lifting doesn’t consist of that. And if you really wanted to I’m sure you could automate the process by using transform.Find().
I’m having the same kind of issues. Working on a project at the moment with just two of us where there’s definitely no strict “finish model first then do all unity programming” workflow (that would leave me sitting around until the modeller was completely finished with his work and also mean he’d never get to see what his work looked like in unity until he wasn’t allowed to change it anymore).
I’ve got a reasonably complex model with moving parts that I’ve attached box colliders to (so it’s a 10 part compound collider). The problem is that every time my modeller updates this model to add cosmetic features etc, I lose all my colliders and have to add them back in and resize/rotate them by hand. I don’t think my issue can be solved by putting my scripting and colliders etc in a parent object, because the colliders need to be attached to the heirarchy in the model, otherwise they wouldn’t move properly with the individual parts when it animates.
Has anyone had similar issues with something that absolutely must be attached to a model?
This is insane . I was glad everything was working really well, till I tried to connect a script to my object. It broke the prefab and now it is no longer updated, when I do any changes to the scene in C4D… That is really bad!
Here´s my problem. I´m building the entire scene in C4D. The “asset prefab” works fine, everytime I change anything in C4D the scene gets updated. Not only the structure but also the position of the object in the scene and the material.
Now I would like to connect a script to my object, but voilá…I get a “be careful…braking prefab notice.” If I click on okay, I can add my script, but the scene is no longer updated.Structure yes, not no changes on position or material.
Please, this is really important for us… How can I add scripts to objects, but still keep them as an “asset prefab” ?
Ha, and I thought I was going insane.
The latest update didn’t fix/change it either, what a shame. So if I change the model, even when just moving a part a tiny bit, I have to reattach all the scripts, particle emitters etc. What a pain. Updates nicely though when not using a prefab (not that that would help in any way)
Would be sweet to find a solution since it’s otherwise so much fun to work with Unity.
This is major…I just found this behaviour in Unity you all talk about and i cant believe it…This is a big problem…
Every time you must update or add something to a prefab you have to connect everything again… Jesus…
All this years of development and such an issue ?! Oh Unity Unity…I feel sad…Whay is this so? And why nobody from Unity answers to this thread? This is unebelievable time consuming issue…
I realy dont understand why this cant be fixed and why people didnt complain about this?
I doubt this cant be fixed by developers. Its not so big thing from my point of view but it would bee a HUGE time saver in the Unity workflow…
I also used to complain about it until by chance I found the solution which seems so obvious now…
Say you got a prefab wich includes :
a mesh (“mesh filter”)
a mesh renderer
some materials
collider
scripts
and whatever else.
1/ You import your new model in Unity (WITHOUT trashing the previous version yet).
2/ You select you prefab in the Project tab (of course not in the scene tab)
3/ in the inspector you select for example the mesh filter (just above “transform” block) and you go and replace the mesh by the new one,
(click on the mesh and you’ll see the “select mesh” pop window, then just pick the new one).
You got it.
Do the same for all items you have to update (materials, mesh collider for example).
And ONLY WHEN you’re sure your prefab does not use any part / item of the previous version of your imported model, then you can trash it.
This way you won’t lose any of your scripts or whatever attached elements.
Guess many of us use to think (wrong) at first that you should “updating” a prefab model by drag-dropping the new imported model on the prefab icon. Which clearly distroys everything.
The correct way is selecting items in the prefab itself and changing only what is needed.