Why can't you set the OnClick parent object on a prefab of the button?

I created a prefab of the buttons and am using that, but it won’t let me drag the Quiz Canvas in there. It works fine doing it for each individual button, as shown in the video, and everything works fine.

It would be better if that could be set in the prefab for the buttons though. That way you would only have to set the value for the passed integer.

Do I possibly have to set this in the button prior to creating the prefab, or would that setting be lost when I drag such a button into the Prefab folder?

To me this seems like a bug in the Unity Editor and it should allow you to set it in the prefab.

Hi,

By prefab, you are referring to the prefabs in the Assets folder? And the Quiz Canvas is a game object in the Hierarchy? If so, the prefab cannot reference the Quiz Canvas because game objects in the Hierarchy get destroyed during runtime, which contradicts the purpose of prefabs.

Yes, a prefab in the Assets folder (a sub-folder I create there called Prefabs). At the start of where you create the buttons for Quiz Master he did them as Prefabs, but then said you didn’t have to do that and Prefabs would be discussed in a later lesson.

BTW - Just for grins I created a button with the objects assigned to the [SerializeField] variables and when I dragged it into the Prefabs folder the version in there loses those settings. So what you say is probably correct and you can’t assign a prefab something that is in the Hierarchy. First time I ever ran into that with a Prefab, which is why I asked.

Thanks

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms