- Home /
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.
anyone? there is only one line I need help with :
Transform targetTransform = target.Find(sourceTransform.name);
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
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.
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.
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. :)
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 ...
Your answer
Follow this Question
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