Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Velketor · Nov 29, 2012 at 01:01 AM · gameobjectprefabfunctioncloneconnection

Cloned Prefab

I instantiate a prefab and it becomes a clone, for example:

prefab1 now becomes prefab1(Clone).

Unfortunately, I'm losing my prefab connection because of it:

 var Hero : GameObject;
 
 function Update () {
     transform.position.x = Hero.position.x;
     transform.position.y = Hero.position.y + 10;
 }

How can I reference the cloned prefab instead of just the prefab itself? Any help is appreciated. Thank you.

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
Best Answer

Answer by CostelloNicho · Nov 29, 2012 at 04:22 AM

Try this: ( adapted from your comments )

 var hero;
 
 void Start(){
      hero = GameObject.FindWithTag("Player"); //be sure to set the tag on the correct object
 }
 
 void Update(){
       hero.transform.position.x =hero.transform.position.x;
       hero.transform.position.y = hero.transform.position.y + 10;
 }

 
 
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 Velketor · Nov 29, 2012 at 04:34 AM 0
Share

thank you for the post. i get the error 'void is not a valid macro'

avatar image CostelloNicho · Nov 29, 2012 at 04:40 AM 0
Share

Sorry about that I'm a C# programmer. Happy I could help though

avatar image Velketor · Nov 29, 2012 at 04:44 AM 0
Share

this worked for me! thx again friend!

var hero;

function Update(){ hero = GameObject.FindWithTag("Player"); //be sure to set the tag on the correct object transform.position.x = hero.transform.position.x; transform.position.y = hero.transform.position.y + 10; }

avatar image
-1

Answer by MountDoomTeam · Nov 29, 2012 at 01:46 AM

How can you lose the prefab connection? I think you only do that if you change the prefab contents? And it gives a warning. how to reference cloned prefab?

instantiating a GameObject in the scene is the same as duplicating it. you simply say

  instantiate(instantiated GameObject, position, rotation);

just reference it the same as if you are going to do a rotation on it, except duplicate it,it's in the same script?

people prefer it when you write an actual question title because it's the academically proper educated way of corresponding in writing in public forums. writing clone prefabs is a bit like having a question called -clicking area- or -pressing button- it's too vague!

Comment
Add comment · Show 5 · 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 Velketor · Nov 29, 2012 at 01:57 AM 0
Share

thanks for the feedback. i have a camera that is linked to a prefab. when the prefab is instantiated into the scene, it becomes "prefab(Clone)" and my camera stops following the player because it can't find the prefab. I need to be able to directly call the "prefab(Clone)" version ins$$anonymous$$d of the regular prefab prior to instantiating. do you know how to do that?

avatar image MountDoomTeam · Nov 29, 2012 at 06:19 AM 0
Share

yes, normally you should link a camera to GameObject already on the scene. find with tag for everything unless you have already as a reference. I didn't answer that you have to findobject with tag because with 326 experience I thought you must be asking something much more complicated! I figured you wanted to duplicate a clone!

I accidentally made a prefab that instantiated itself within itself and it did

prefab(clone)

prefab(clone)(clone)

prefab(clone)(clone)(clone)

prefab(clone)(clone)(clone)(clone)

prefab(clone)(clone)(clone)(clone)(clone)

prefab(clone)(clone)(clone)(clone)(clone)(clone)

$$anonymous$$any hundreds of times:)

avatar image Velketor · Nov 29, 2012 at 12:20 PM 0
Share

thanks but that's not what is happening to me. it's already fixed now. 326 experience doesn't mean i know complicated things. you have 359 and couldn't figure this question out! thx for the help though.

avatar image MountDoomTeam · Dec 03, 2012 at 08:04 AM 0
Share

I figured I should help some people on this forum but I was too sleepy to understand the question! I read it when I wasn't drowsy and I realised I had miss read it!

still, it's important to write questions on the forum as questions and not as titles, it's more adult and practical.

avatar image Velketor · Dec 03, 2012 at 01:04 PM 0
Share

i'll stop being such a child with my titles since it bothers the adults.

avatar image
0

Answer by CostelloNicho · Nov 29, 2012 at 03:23 AM

I'm not sure I understand the problem fully, but I'm assuming your using GameObject.Find() to find whatever your camera is trying to follow, but after instantiating the object the name has "(clone)" at the end.

If this is the case you can do this:

  1. Create a variable to track the instantiated object.

    GameObject trackThisObject;

  2. assign the instantiated object.

    trackThisObject = GameObject.Instantiate( instantiated GameObject, pos, rot);

  3. Use track this object for camera tracking.

Hope this helps, a bit lost by the question.

Comment
Add comment · Show 4 · 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 Velketor · Nov 29, 2012 at 03:45 AM 0
Share

is it possible to have my camera follow an object with the tag "Player" ins$$anonymous$$d of trying to code for the (Clone)?

avatar image Velketor · Nov 29, 2012 at 03:59 AM 0
Share

i get 'object reference is not set to an instance of the object'...how can i reference a cloned prefab directly by name or even tag?

avatar image CostelloNicho · Nov 29, 2012 at 04:11 AM 0
Share

Yes you can find an object by tag:

GameObject.FindWithTag("nameOfObject");

here's a link:

http://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindWithTag.html

avatar image Velketor · Nov 29, 2012 at 04:17 AM 0
Share

yes but how do i actually add it to my code? i tried this: var hero = GameObject.Find("Player");

function Update () { hero.position.x = hero.position.x; hero.position.y = hero.position.y + 10; }

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

12 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

Related Questions

Create customized prefab at runtime and save it 1 Answer

How can I enable/disable a component of a Clone 1 Answer

Deleting a GameObject 2 Answers

How do i apply some AISeeking code to all instances of a sprite, it is contained with the ship it is seeking but only 1 follows it 0 Answers

Update function in a UnityScript attached to 50 clones of a prefab: heavy or not? 1 Answer


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