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 AlucardJay · Apr 12, 2012 at 10:51 AM · c#transformfindconversion

help declaring Transform in Find statement BCE0019

I am doing the 3D Buzz TPC tutorial , and have sucessfully converted all the script to .js up until now. I am at the part of matching the ragdoll rotation to the character rotation.

So, I need help understanding and converting this specific part of code :-

This is the line in C# ->

 void MatchChildrenTransforms(Transform source, Transform target)
     {
         foreach(Transform sourceTransform in source.transform)
             {
                 Transform targetTransform = target.Find(sourceTransform.name);

This is my line in JS ->

 function MatchChildrenTransforms(source : Transform, target : Transform) : void
     {
         for(var sourceTransform in source.transform)
             {
                 var targetTransform = target.Find(sourceTransform.name);

  • this gives the error -> Assets/SCRIPTS_ JS/Script_ TP_ Animator.js(564,83): BCE0019: 'name' is not a member of 'Object'.

I have also tried all of the following combinations :

var targetTransform = target.Find(sourceTransform.name) as Transform;

var targetTransform = target.Find(sourceTransform.transform.name);

var targetTransform = target.Find(transform.sourceTransform.name);

var targetTransform = target.transform.Find(sourceTransform.name);

and even all the combinations with gameObject instead of transform.

the Unity Scripting Reference only shows a string search in -> transform.Find("E.G.");

I feel I have to declare a typecast of Transform somewhere , but this one is eluding me. Any help would be greatly appreciated (I'm 4 video's away from completing Section 4 and the full TPC!)

Link to tutorial : http://www.3dbuzz.com/vbforum/content.php?212 (Section 4 , Part 31)

Working JS conversion up to climbing (just for a laugh): http://www.alucardj.net16.net/examples/TPC-tutorial/TPCterrainworld.html

(and I am a little annoyed at myself for getting this far with searches, except for learning Singleton, then being stuck here on recursion). Thanks , Jay.

Comment
Add comment · Show 1
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 AlucardJay · Apr 12, 2012 at 11:37 AM 0
Share

anyone? there is only one line I need help with :

 Transform targetTransform = target.Find(sourceTransform.name);
 
 

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Kleptomaniac · Apr 12, 2012 at 12:10 PM

Hey mate,

sourceTransform is being dynamically typecast as an Object I believe. You need to declare sourceTransform as a Transform to access child components of source.transform like so:

 for(var sourceTransform : Transform in source.transform)

I believe that should work. :)

Hope that helps, Klep

P.S. By the way man! I'm a mod! Woohoo! :P

Comment
Add comment · Show 7 · 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 AlucardJay · Apr 12, 2012 at 12:25 PM 0
Share

I tried to typcast that (almost) everywhere! Thanks. Although I do get an implicit downcast error :

Assets/SCRIPTS_JS/Script_TP_Animator.js(562,33): BCW0028: WARNING: Implicit downcast from 'Object' to 'UnityEngine.Transform'.

This , however did Not fix it :

 for(var sourceTransform : Transform in source.transform) as Transform

Assets/SCRIPTS_JS/Script_TP_Animator.js(562,82): BCE0043: Unexpected token: as.

But I am happy to imply Transform as Object. It has worked before (when I didn't typcast things in GetComponent), it'll still run. But I cannot run and test it until I finish the next 4 video's. I'l let you know if it works (and mark as accepted).

You're an absolute whizz. Denounce your noob status NOW! In the couple of weeks that I saw you pop-up on this 'site, watched the karma rise daily, all the corrections on other posts, and all the helpful correct comments you put up (including all the noob ones I was trying to mop up and gain some karma from), I have been blown away. Definitely an asset to this 'site (how was that for a suck-up?). I better watch my suggested code (and temper) from now. Well done dude, you deserve it.

avatar image AlucardJay · Apr 12, 2012 at 12:30 PM 0
Share

did you have a look at my other Casting Qn?

http://answers.unity3d.com/questions/238960/spherecasting-and-colliders.html

or was the LineCast a bad enough experience! I have to learn Layermask and layers in general now. Ok, I'll stop the off-topic chat now. Thanks again.

avatar image Kleptomaniac · Apr 12, 2012 at 12:41 PM 1
Share

Yeah, don't worry about the warning. I asked about that a while ago ... don't worry about it, it's just a side effect of using #pragma strict on that type of for loop ... just use #pragma implicit to rectify. :)

What that target.Find is actually trying to find a child of that name from the array of transforms generated from the for loop ... for more info check out Transform.Find. :)

Anyway, aside from the WARNING, did it get rid of your Object.name error?

Haha, thanks man ... means a lot! You're damned awesome too!

I'll check out your other question now. :)

avatar image AlucardJay · Apr 12, 2012 at 12:48 PM 0
Share

sry , yeah , all errors now gone. I cannot test if this is setting the ragdoll limb pos/rot 's correctly until I finish. Should be there in about 1 hour, but I am quietly confident ...

avatar image Kleptomaniac · Apr 12, 2012 at 03:21 PM 1
Share

Yay! :) Glad I could help man. :P

Show more comments

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

Js to c# conversion 1 Answer

Distribute terrain in zones 3 Answers

C# The call is ambiguous between the following methods or properties 1 Answer

Converting this JS code to C# 1 Answer

js to C# - Transform 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