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 /
This question was closed Dec 01, 2012 at 08:38 PM by code-blep for the following reason:

Not answered as unable to fully explain. Decided to approach another way.

avatar image
0
Question by code-blep · Dec 01, 2012 at 04:02 PM · getcomponentstringpathdynamicinsert

Using a String to populate GetComponent

Hi,

I need to dynamically create the 'Path' to a boolean value in an external script, but I get the following error:

MissingFieldException: Field 'SpawnAttackersAndDefenders.spawnModeIdentity' not found.

Here is the code so far:

 var spawnAttackersAndDefendersScript : SpawnAttackersAndDefenders;
 
 //The script that spawns the object this is attached to advises the name of the boolean to be changed
 var spawnModeIdentity : String;
 
 function Start(){
 
     spawnAttackersAndDefendersScript = GameObject.Find("Start").GetComponent(SpawnAttackersAndDefenders);
     
     spawnAttackersAndDefendersScript.spawnModeIdentity = true; //Script fails here
 }
 
 function OnTriggerEnter (other : Collider) {
     
     spawnAttackersAndDefendersScript.spawnModeIdentity = false; //Script fails here
 }

How do it correctly 'insert' the name of the boolean variable I am trying to target?

[UPDATE] To clarify, the var 'spawnModeIdentity' is NOT the real name of the boolean I am trying to target. It is simply a way of dynamically changing which boolean to target.

For example:

Script A has 3 Booleans:

var test1 = true;

var test2 = true;

var test3 = true;

Script B is designed to dynamically target only one of the Booleans in script A. Script A tells which Boolean Script B is to target using the following code:

scriptB.spawnModeIdentity = "test1"

This part is working fine.

From there I am trying to then correctly pass the new Boolean back to the relevant Boolean in Script A.

Thanks

Paul

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

1 Reply

  • Sort: 
avatar image
1

Answer by fafase · Dec 01, 2012 at 04:06 PM

You are trying to pass a boolean to a string. I think you want to do:

 spawnAttackersAndDefendersScript.spawnModeIdentity = "true";

But why not using a boolean from the start?

Comment
Add comment · Show 2 · 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 code-blep · Dec 01, 2012 at 04:50 PM 0
Share

Hi fafase,

Thanks for responding. However that is not what I am trying to do. I have updated my question, to try and explain better. It's sometimes feels harder to explain than the actual problem itself.

avatar image code-blep · Dec 01, 2012 at 08:37 PM 0
Share

I have worked around the problem in a different way, and will be closing this question. Thank you for assisting fafase.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Generate players path on the Fly 1 Answer

Passing a Script Name to a Function 2 Answers

C# How to make String Dynamic for UnityEvent 0 Answers

Can i give GetComponent a variabel instead of a scriptname? 1 Answer

Store the path with Resources.Load in a string 3 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