Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 grimofdoom · Jul 22, 2015 at 02:57 PM · unity5

Setting parent causing unknown problems

I am trying to text a text box running, so the player can kinda get a story perspective as they play my game, and so they can know other important stuff. Right now, my script is producing the errors

=The best overloaded method match for UnityEngine.Transform.SetParent(UnityEngine.Transform)' has some invalid arguments =Argument #1' cannot convert UnityEngine.GameObject' expression to type UnityEngine.Transform'

I am calling the function form outside of the actual script, not sure that is what is causing the problem at all. The parent object that the text prefab is going into has a grid layout, so it should fall in line(as i guessed) when it works(so the original instantiate location of it should bear no unwanted results as i am guessing)

 using UnityEngine;
 using System.Collections;
 
 public class TextBox : MonoBehaviour {
 
     public GameObject TextObject;
     public GameObject TextArea;
 
     public void AddText(string Words){
 //I do not know any other way of temp hiding a gameobject that works, but this works
         Instantiate (TextObject, new Vector3 (99999, 99999, 99999), Quaternion.identity);
         UnityEngine.UI.Text displayedtext = TextObject.GetComponent<UnityEngine.UI.Text>();
         Words = "| " + Words;
         displayedtext.text = Words;
         TextObject.transform.SetParent (TextArea);
     }
 }
 
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Dave-Carlile · Jul 22, 2015 at 02:58 PM

If you go look up the documentation for Transform.SetParent, you'll see that the parameter it expects is of type Transform. You're passing in a parameter of type GameObject. This is also what the error message is telling you. Pass in TextArea.transform instead.

Comment
Add comment · 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
0

Answer by Cherno · Jul 22, 2015 at 02:59 PM

As evident from the error message, you are trying to pass a GameObject (TextArea) to the SetParent function, but it only accepts a Transform.

 TextObject.transform.SetParent (TextArea.transform);
Comment
Add comment · Show 3 · 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 grimofdoom · Jul 22, 2015 at 10:28 PM 0
Share

i fixed that one, i feel stupid. But now i get the error of:

[Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.]

which is strange to me(never had this error before)

avatar image fuego_see_money · Jul 22, 2015 at 11:25 PM 0
Share

Usually that means you aren't actually setting the parent to a GameObject, but rather a Prefab (non-instantiated). You should make sure that you set the parent to an actual instantiated GameObject; not a Prefab living in a folder somewhere (e.g. Assets/Prefabs/Rock.prefab)

avatar image grimofdoom · Jul 22, 2015 at 11:59 PM 0
Share

O$$anonymous$$. When I instantiate the object, what do I define "SpawnedText" as, so that it will work correctly? i tried "Object SpawnedText;", but then i cannot setparent.

 using UnityEngine;
 using System.Collections;
 
 public class TextBox : $$anonymous$$onoBehaviour {
 
     public GameObject TextObject;
     public GameObject TextArea;
 
     public void AddText(string Words){
                 //define SpawnedText here
         SpawnedText = Instantiate (TextObject, new Vector3 (99999, 99999, 99999), Quaternion.identity);
         UnityEngine.UI.Text displayedtext = SpawnedText.GetComponent<UnityEngine.UI.Text>();
         Words = "| " + Words;
         displayedtext.text = Words;
         SpawnedText.transform.SetParent (TextArea.transform,true);
     }
 }
 
avatar image
0

Answer by grimofdoom · Jul 23, 2015 at 10:55 AM

Solved it completely, Apperently this works

 GameObject NewObject = instantiate(prefab);
 NewObject.Transform.SetParent = ParentObject.Transform;

but this did not:

 GameObject NewObject = instantiate(prefab, new vector 3 (999,999,999), quaterniun.identity);
 NewObject.Transform.SetParent = ParentObject.Transform;










Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Sample-precise sync on multiple audio sources ? 1 Answer

Failed to re-package resources 0 Answers

Unity 5.3 Grey Screen - Doesn't Open 1 Answer

i need some help with 1 Answer

GL POINT_SIZE doesn't works in BUILD on Linux Unity Editor 5.4.3f1. Works only in Editor 0 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