- Home /
Apply only one Component to Prefab - Editor Scripting
Hello.
I am doing one extension for Unity and i need to add buttons to Apply certain component to a prefab.
Is that possible through code? So if i have a cube with BoxCollider and MonoBehaviour and i change something on the MonoBehaviour i want to apply to the Prefab, only the changes made, to the MonoBehaviour and not on the BoxCollider....
There is: PrefabUtility.SetPropertyModifications, but that applies all Components, to the Prefab...
If there is no command for this, coud you please suggest some workaround..
thanks
Do u basically want permanent changes in prefab in runtime using the instance gameobject in scene?
No. I know, that i can copy the component.
I want to apply the changes made to certain component to it's prefab component.
It's not for runtime...
Just click apply? why would you need to do it in code if its not in runtime? Why make it difficult when It can go easy?
Answer by Wanzyee · Jan 07, 2016 at 07:01 PM
Find the prefab source of the instance, there should be API in PrefabUtility.
Confirm the hierarchy relation carefully.
Use GetComponents() to check the component order, in case you have multiple ones of the same type.
Copy instance component's members and paste to the prefab one you found above.
The method code, to copy and paste component, can be found on Answer or Store. Find the relatives, cheers!
@Wanzyee thanks, i have allready wrote as comment, that, this is in my head, as the only way of doing it...
And this is exactly how i did it... Anyway i'll accept that anwer so the question doesn't stay unanswered..
cheers
@instruct9r lol, I just saw the "show more comments"... but let this be answered is still good, thx... cheers~
Your answer
Follow this Question
Related Questions
Set a Prefab's variable when you instantiate it, but before it calls Awake? 2 Answers
Accessing component of a single prefabs' instance. 0 Answers
Apply Changes to Prefab - Unity 2018 0 Answers
The variable othertransform of Prefab has not been assigned 2 Answers
get component on prefab in script C# 1 Answer