Okay, I’ve got another small problem. I currently have a rather large scene full of geometry and their various scripts.
Now, because I’ve attached scripts directly onto the models, I’ve lost the connections to the original meshes, so I cant update them and maintain my scripts at the same time.
The solution I’ve come across is to use a parental GameObject and attach the scripts to it, however, as I’ve imported scenes into Unity, all of my geometry already has a parent node with the file name. Any attempt to change this breaks the prefab.
So, the only thing I can think of is to break up the scene to separate meshes that will have scripts, and those that wont, and THEN to create parental objects to hold the scripts.
Is this the only way I can keep the scripts in my scene on my meshes, while still being able to modify their appearance, or is there another way? Will there ever be a way in future?
what you are looking to use is actually exactly prefabs, as you can have scripts + update the visual part.
breaking prefabs is, as long as not overdone, no problem.
you can just use the “apply to prefab” function in the game object menu to relink it and update all prefabs for example
Normally you would first think about the structure of your object and only place pure visual - collision stuff in the scene and add the scripts to prefabs then that are reusable. You are currently “on the opposite side” and will likely have to go a few steps back or take an extra round to get to that clean point again.
You can, but you might not want to. It is sometimes better to put the model inside a parent object and put any scripts or other components on the parent.
Okay, but that also means I have to write/re-write my scripts to take children into consideration doesn’t it? Or does my geometry stay as just static polygons and my scripts work on the empty parents?
I’ve come up with an idea to solve my problem. Currently I’ve been using a single scene file from Blender as my geometry, so if I change anything I lose the prefab.
So instead, I’ll use my Blender scene files for just the static geometry that wont ever have scripts/animation, and I’ll import separate object files for other geometry, along with parental Unity objects.
Does this sound like it should work or can anyone think of a better way?
I’ve encountered this problem as well. Typically I have the scripts in the parent game object, but animation callbacks will only work (or even populate the dropdown box) if the script is directly attached to the model.
Why doesn’t the model just stay in sync? When you make it a prefab, does it actually make a copy of the model data?
It’s pretty irritating to be working on the functionality and have an artist give me an updated mesh, and then have to start all over again with the animation callbacks. Fortunately it’s just one script and a handful of animation overrides… for now. I can see it getting really obnoxious down the road with subtle tweaks to the source Maya file and constantly fixing up the prefab.
Is there a good solution for this? I have the same issue with wanting animation callbacks, but if I attach a script to the model, it loses its prefab connection. How do people go about this?
1- Drag your model at the scene
2- Create a new prefab
3- Drag your model from the scene to the new prefab
4- Add any desired script to the model at the scene (now a real prefab), even if it breaks prefab connection
5- Use the menu option “apply to prefab”
This way you should still be able to change the model in Blender (within some limits) and get your prefab updated automatically. Limits: you cannot add new bones or delete existing ones, and you cannot add new objects or delete existing ones. But you can add more animations (you will only need to manually update the animation list of the prefab), or new geometry inside the same objects.