Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

PrefabUtility.ApplyPrefabInstance isn´t working :(

Discussion in 'Scripting' started by BenniLoeb, Apr 2, 2021.

  1. BenniLoeb

    BenniLoeb

    Joined:
    Aug 31, 2019
    Posts:
    1
    Hi,
    I´m currently working on implementing upgrades to my game.

    I have a GameObject which my upgrade script is attached to and at first (because I want my upgrades in different Scenes) I used a Singleton Pattern so that my upgrades stay the same, even if you load a new Scene.
    But the problem is, that in the other scenes, in which my Singleton Pattern destroyed the initial Upgrade GameObject, which I had dragged in to other GameObjects (in other words attached with public or [SerializeField]).
    Now of course the GameObjects that had the initial Upgrade GameObject attached to them, didn´t do what they were supposed to do.

    So I´m trying to use Prefabs to make all the upgrades be the same in every script.
    That´s why I "told" the Upgrade GameObject to apply all the changes I made to every other PrefabInstance
    with PrefabUtility.ApplyPrefabInstance:

    [SerializeField] GameObject myPrefab; //Dragged In Itself In Unity

    void Update()
    {
    PrefabUtility.ApplyPrefabInstance(myPrefab, InteractionMode.AutomatedAction);
    }

    (Of course a really simplified version)

    But the weird thing is Unity is "telling" me, I can´t apply methods on an object which is not part of a Prefab instance is not supported.

    Can you help?
     
  2. ahmethamdi487

    ahmethamdi487

    Joined:
    Dec 10, 2021
    Posts:
    7
    having the same problem. hope someone explains how to get rid of it
     
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,224
    How about checking the other methods in the PrefabUtility class?