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 jeffreyrampineda · Jan 10, 2015 at 04:49 PM · referenceinactive

Setting up reference to an inactive GameObject through script

Is this not allowed? I have tried setting up a reference to an inactive GameObject through script using the Awake() method. Unfortunately, I always end up with null. I know that it would work if I set up the references using the UnityEditor properties by dragging but I would prefer setting them up using a script in cases of having the reference holder being non-existent yet (Instantiating during run time).

Comment
Add comment · Show 3
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 UnityKen · Jan 10, 2015 at 04:55 PM 0
Share

If the script is attached to the game object that is inactive then nothing would work in that script

avatar image Mmmpies · Jan 10, 2015 at 05:00 PM 0
Share

There's always different ways of getting round things, what is it you want to get access to for that GameObject?

Chances are it can either be handled when the object gets instantiated or held in another GameObject and only used by that GameObject when it's active.

avatar image jeffreyrampineda · Jan 10, 2015 at 06:44 PM 0
Share

I have a "gameObject A" with "Script A" that does not exist yet because it is to be instantiated during runTime. I also have "gameObject B" that currently exists in the game already but is Inactive.

After the "gameObject A" is instantiated, I want it's "Script A" to set up a reference to the inactive "gameObject B".

The problem is that whenever I set the reference using "script A" gameObject reference = GameObject.Find("gameObject B"); It always ends up null.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mmmpies · Jan 10, 2015 at 07:38 PM

OK, so instead of setting that when gameObjectA is instantiated why not do this...

Make gameObjectB a prefab and instantiate it when needed, from the script that instantiates it hold a reference to ScriptA and have a public function in ScriptA to pickup gameObjectB and when you instantiate gameObjectB call that function just afterwards.

It should pick up the newly instantiated object once it's there.

Do you need help with the scripting and if yes javascript or C#?

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 jeffreyrampineda · Jan 11, 2015 at 02:05 AM 0
Share

I'm very sorry for the late reply but I will try out your method.

Also, thank you but I don't need help with scripting. I like doing scripts myself since I see it as learning.

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

How Can i Reference String another Script? 2 Answers

How do I reference an object's rotation through an attached script? 1 Answer

"Object Reference not set to an instance of an object" 1 Answer

How to reference another script and call a function in C# ? 2 Answers

Does a reference to a script have up-to-date info ? 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