Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dcostadc · May 13, 2019 at 04:11 PM · instantiatehierarchy

How to make instantiated buttons permanent in hierarchy?

Hi, I´m trying to add one button whenever something is added to a database. I already did the connection to the DB and put it to add an instantiated button when something is added in it. Here is my code so far

 string MyConnection1 = "datasource=...;port=..;username=..;password=..";
         string Query1 = "select Name" +
             " from ..." +
             "ORDER BY ID DESC LIMIT 1;";
         MySqlConnection MyConn1 = new MySqlConnection(MyConnection1);
         MySqlCommand MyCommand1 = new MySqlCommand(Query1, MyConn1);
         MyConn1.Open();
         MySqlDataReader readr = MyCommand1.ExecuteReader();
         //int Value = MyCommand2.ExecuteNonQuery();
         while (readr.Read())
         {
             nam = Convert.ToString(readr[0]);
             Debug.Log("val = " + nam);
         }
         //MyCommand2.ExecuteNonQuery();
         MyConn1.Close();
 
         GameObject newButton = Instantiate(button) as GameObject;
         newButton.transform.SetParent(content.transform, false);

The problem is that it only works on runtime. When I stop the game, the buttons dissapear and I want them to be saved in hierarchy. Can anyone help me solve this? Thanks!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DCordoba · May 13, 2019 at 05:07 PM 0
Share

try this:

create a empty prefab

while playing drag & drop the button to the prefab

stop playing and drag & drop the prefab with the button to the hierachy

avatar image dcostadc DCordoba · May 14, 2019 at 10:18 AM 0
Share

Hi, thanks for the reply This could be a solution but not for what i'm trying to do. I want it to be created and saved automatically, without the user having to do something. Is it possible?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · May 14, 2019 at 11:08 AM

well thats a hard task, you can use this example for saving objects created at runtime BUT since is using unity editor it wont work in builds just during editor playmode LINK. if you want to use this for builds just save your buttons in some kind of txt or xml that you can parse (or call the DB at the start of the game) and spawn the buttons then, this is also valid for editor (but wont edit unity scene).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DCordoba · May 14, 2019 at 05:07 PM 0
Share

yes, like a savegame, or part of the savegame that was created the button, he use a sql database there, so, is probably that he want use the same way, creating the previous buttons dynamically by script when load a save/start the game...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate script for randomly selecting sound is suddenly creating New Game Object in hierarcy?? 2 Answers

Instantiate a prefab inside a hiearcy 1 Answer

GameObject Instantiate and check if "activeInHierarchy" (HELP) 0 Answers

Is there a way to make clones appear as children in the hierarchy? 3 Answers

Destroying a prefab doesn't remove it from the Hierarchy list 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges