Why is this transform set in this Unity script?

Multi tool use
I have been following this great tutorial:
https://www.youtube.com/watch?v=uxrKE2VKvmc
and at some point it does this for each target, it creates a gameObject ?
If you look at the code here:
private void SetupTargets(List<TrackableBehaviour> allTargets)
{
Debug.Log("Listing all Targets names:");
foreach (TrackableBehaviour target in allTargets)
{
Debug.Log("Target's name:" + target.TrackableName);
target.gameObject.transform.parent = transform;
target.gameObject.name = target.TrackableName;
target.gameObject.AddComponent<PlaneManager>();
Debug.Log(target.TrackableName + " created!");
}
}
why this line of code ?
target.gameObject.transform.parent = transform;
If I comment it out it still works fine..
The full class code is below:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
using System.Linq;
public class TargetManager : MonoBehaviour
{
public String mStartingMarkerDatabaseName = "";
private List<TrackableBehaviour> mAllTargets = new List<TrackableBehaviour>();
private void Awake()
{
VuforiaARController.Instance.RegisterVuforiaStartedCallback(onVuforiaStarted);
}
private void onDestroy()
{
VuforiaARController.Instance.UnregisterVuforiaStartedCallback(onVuforiaStarted);
}
private void onVuforiaStarted()
{
LoadDatabase(mStartingMarkerDatabaseName);
mAllTargets = GetTargets();
SetupTargets(mAllTargets);
}
private void LoadDatabase(string name)
{
ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
objectTracker.Stop();
if (DataSet.Exists(name))
{
DataSet dataSet = objectTracker.CreateDataSet();
dataSet.Load(name);
objectTracker.ActivateDataSet(dataSet);
}
objectTracker.Start();
}
private List<TrackableBehaviour> GetTargets()
{
List<TrackableBehaviour> allTrackables = new List<TrackableBehaviour>();
allTrackables = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours().ToList();
return allTrackables;
}
private void SetupTargets(List<TrackableBehaviour> allTargets)
{
Debug.Log("Listing all Targets names:");
foreach (TrackableBehaviour target in allTargets)
{
Debug.Log("Target's name:" + target.TrackableName);
target.gameObject.transform.parent = transform;
target.gameObject.name = target.TrackableName;
target.gameObject.AddComponent<PlaneManager>();
Debug.Log(target.TrackableName + " created!");
}
}
}
unity3d augmented-reality vuforia
add a comment |
I have been following this great tutorial:
https://www.youtube.com/watch?v=uxrKE2VKvmc
and at some point it does this for each target, it creates a gameObject ?
If you look at the code here:
private void SetupTargets(List<TrackableBehaviour> allTargets)
{
Debug.Log("Listing all Targets names:");
foreach (TrackableBehaviour target in allTargets)
{
Debug.Log("Target's name:" + target.TrackableName);
target.gameObject.transform.parent = transform;
target.gameObject.name = target.TrackableName;
target.gameObject.AddComponent<PlaneManager>();
Debug.Log(target.TrackableName + " created!");
}
}
why this line of code ?
target.gameObject.transform.parent = transform;
If I comment it out it still works fine..
The full class code is below:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
using System.Linq;
public class TargetManager : MonoBehaviour
{
public String mStartingMarkerDatabaseName = "";
private List<TrackableBehaviour> mAllTargets = new List<TrackableBehaviour>();
private void Awake()
{
VuforiaARController.Instance.RegisterVuforiaStartedCallback(onVuforiaStarted);
}
private void onDestroy()
{
VuforiaARController.Instance.UnregisterVuforiaStartedCallback(onVuforiaStarted);
}
private void onVuforiaStarted()
{
LoadDatabase(mStartingMarkerDatabaseName);
mAllTargets = GetTargets();
SetupTargets(mAllTargets);
}
private void LoadDatabase(string name)
{
ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
objectTracker.Stop();
if (DataSet.Exists(name))
{
DataSet dataSet = objectTracker.CreateDataSet();
dataSet.Load(name);
objectTracker.ActivateDataSet(dataSet);
}
objectTracker.Start();
}
private List<TrackableBehaviour> GetTargets()
{
List<TrackableBehaviour> allTrackables = new List<TrackableBehaviour>();
allTrackables = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours().ToList();
return allTrackables;
}
private void SetupTargets(List<TrackableBehaviour> allTargets)
{
Debug.Log("Listing all Targets names:");
foreach (TrackableBehaviour target in allTargets)
{
Debug.Log("Target's name:" + target.TrackableName);
target.gameObject.transform.parent = transform;
target.gameObject.name = target.TrackableName;
target.gameObject.AddComponent<PlaneManager>();
Debug.Log(target.TrackableName + " created!");
}
}
}
unity3d augmented-reality vuforia
add a comment |
I have been following this great tutorial:
https://www.youtube.com/watch?v=uxrKE2VKvmc
and at some point it does this for each target, it creates a gameObject ?
If you look at the code here:
private void SetupTargets(List<TrackableBehaviour> allTargets)
{
Debug.Log("Listing all Targets names:");
foreach (TrackableBehaviour target in allTargets)
{
Debug.Log("Target's name:" + target.TrackableName);
target.gameObject.transform.parent = transform;
target.gameObject.name = target.TrackableName;
target.gameObject.AddComponent<PlaneManager>();
Debug.Log(target.TrackableName + " created!");
}
}
why this line of code ?
target.gameObject.transform.parent = transform;
If I comment it out it still works fine..
The full class code is below:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
using System.Linq;
public class TargetManager : MonoBehaviour
{
public String mStartingMarkerDatabaseName = "";
private List<TrackableBehaviour> mAllTargets = new List<TrackableBehaviour>();
private void Awake()
{
VuforiaARController.Instance.RegisterVuforiaStartedCallback(onVuforiaStarted);
}
private void onDestroy()
{
VuforiaARController.Instance.UnregisterVuforiaStartedCallback(onVuforiaStarted);
}
private void onVuforiaStarted()
{
LoadDatabase(mStartingMarkerDatabaseName);
mAllTargets = GetTargets();
SetupTargets(mAllTargets);
}
private void LoadDatabase(string name)
{
ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
objectTracker.Stop();
if (DataSet.Exists(name))
{
DataSet dataSet = objectTracker.CreateDataSet();
dataSet.Load(name);
objectTracker.ActivateDataSet(dataSet);
}
objectTracker.Start();
}
private List<TrackableBehaviour> GetTargets()
{
List<TrackableBehaviour> allTrackables = new List<TrackableBehaviour>();
allTrackables = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours().ToList();
return allTrackables;
}
private void SetupTargets(List<TrackableBehaviour> allTargets)
{
Debug.Log("Listing all Targets names:");
foreach (TrackableBehaviour target in allTargets)
{
Debug.Log("Target's name:" + target.TrackableName);
target.gameObject.transform.parent = transform;
target.gameObject.name = target.TrackableName;
target.gameObject.AddComponent<PlaneManager>();
Debug.Log(target.TrackableName + " created!");
}
}
}
unity3d augmented-reality vuforia
I have been following this great tutorial:
https://www.youtube.com/watch?v=uxrKE2VKvmc
and at some point it does this for each target, it creates a gameObject ?
If you look at the code here:
private void SetupTargets(List<TrackableBehaviour> allTargets)
{
Debug.Log("Listing all Targets names:");
foreach (TrackableBehaviour target in allTargets)
{
Debug.Log("Target's name:" + target.TrackableName);
target.gameObject.transform.parent = transform;
target.gameObject.name = target.TrackableName;
target.gameObject.AddComponent<PlaneManager>();
Debug.Log(target.TrackableName + " created!");
}
}
why this line of code ?
target.gameObject.transform.parent = transform;
If I comment it out it still works fine..
The full class code is below:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
using System.Linq;
public class TargetManager : MonoBehaviour
{
public String mStartingMarkerDatabaseName = "";
private List<TrackableBehaviour> mAllTargets = new List<TrackableBehaviour>();
private void Awake()
{
VuforiaARController.Instance.RegisterVuforiaStartedCallback(onVuforiaStarted);
}
private void onDestroy()
{
VuforiaARController.Instance.UnregisterVuforiaStartedCallback(onVuforiaStarted);
}
private void onVuforiaStarted()
{
LoadDatabase(mStartingMarkerDatabaseName);
mAllTargets = GetTargets();
SetupTargets(mAllTargets);
}
private void LoadDatabase(string name)
{
ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
objectTracker.Stop();
if (DataSet.Exists(name))
{
DataSet dataSet = objectTracker.CreateDataSet();
dataSet.Load(name);
objectTracker.ActivateDataSet(dataSet);
}
objectTracker.Start();
}
private List<TrackableBehaviour> GetTargets()
{
List<TrackableBehaviour> allTrackables = new List<TrackableBehaviour>();
allTrackables = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours().ToList();
return allTrackables;
}
private void SetupTargets(List<TrackableBehaviour> allTargets)
{
Debug.Log("Listing all Targets names:");
foreach (TrackableBehaviour target in allTargets)
{
Debug.Log("Target's name:" + target.TrackableName);
target.gameObject.transform.parent = transform;
target.gameObject.name = target.TrackableName;
target.gameObject.AddComponent<PlaneManager>();
Debug.Log(target.TrackableName + " created!");
}
}
}
unity3d augmented-reality vuforia
unity3d augmented-reality vuforia
asked Dec 30 '18 at 12:32
Trt TrtTrt Trt
2,06993767
2,06993767
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
target.gameObject.transform.parent = transform;
That code means that the target gameObject will be a child of whatever gameObject the TargetManager script is attached to.
As derHugo pointed out in the comments, it's redundant and can just be written as
target.transform.parent = transform;
The target manager is just under the "SampleScene"... So it has no parent ?
– Trt Trt
Dec 30 '18 at 19:36
Correct. The target manager itself has no parent.
– Sean Carey
Dec 30 '18 at 19:42
So that line of code makes no sense... ?
– Trt Trt
Dec 30 '18 at 19:43
No, the target manager has no parent. But we're not talking about the target manager. We're talking about the individual targets themselves. Those will be children of the target manager.
– Sean Carey
Dec 30 '18 at 19:45
1
In simple it just means thattarget
will be a child ofTargetManager
. It's a bit redundant though:target.transform.parent =...
would be enough ;)
– derHugo
Dec 30 '18 at 21:01
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53977613%2fwhy-is-this-transform-set-in-this-unity-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
target.gameObject.transform.parent = transform;
That code means that the target gameObject will be a child of whatever gameObject the TargetManager script is attached to.
As derHugo pointed out in the comments, it's redundant and can just be written as
target.transform.parent = transform;
The target manager is just under the "SampleScene"... So it has no parent ?
– Trt Trt
Dec 30 '18 at 19:36
Correct. The target manager itself has no parent.
– Sean Carey
Dec 30 '18 at 19:42
So that line of code makes no sense... ?
– Trt Trt
Dec 30 '18 at 19:43
No, the target manager has no parent. But we're not talking about the target manager. We're talking about the individual targets themselves. Those will be children of the target manager.
– Sean Carey
Dec 30 '18 at 19:45
1
In simple it just means thattarget
will be a child ofTargetManager
. It's a bit redundant though:target.transform.parent =...
would be enough ;)
– derHugo
Dec 30 '18 at 21:01
|
show 2 more comments
target.gameObject.transform.parent = transform;
That code means that the target gameObject will be a child of whatever gameObject the TargetManager script is attached to.
As derHugo pointed out in the comments, it's redundant and can just be written as
target.transform.parent = transform;
The target manager is just under the "SampleScene"... So it has no parent ?
– Trt Trt
Dec 30 '18 at 19:36
Correct. The target manager itself has no parent.
– Sean Carey
Dec 30 '18 at 19:42
So that line of code makes no sense... ?
– Trt Trt
Dec 30 '18 at 19:43
No, the target manager has no parent. But we're not talking about the target manager. We're talking about the individual targets themselves. Those will be children of the target manager.
– Sean Carey
Dec 30 '18 at 19:45
1
In simple it just means thattarget
will be a child ofTargetManager
. It's a bit redundant though:target.transform.parent =...
would be enough ;)
– derHugo
Dec 30 '18 at 21:01
|
show 2 more comments
target.gameObject.transform.parent = transform;
That code means that the target gameObject will be a child of whatever gameObject the TargetManager script is attached to.
As derHugo pointed out in the comments, it's redundant and can just be written as
target.transform.parent = transform;
target.gameObject.transform.parent = transform;
That code means that the target gameObject will be a child of whatever gameObject the TargetManager script is attached to.
As derHugo pointed out in the comments, it's redundant and can just be written as
target.transform.parent = transform;
edited Dec 30 '18 at 21:26
answered Dec 30 '18 at 19:29
Sean CareySean Carey
41528
41528
The target manager is just under the "SampleScene"... So it has no parent ?
– Trt Trt
Dec 30 '18 at 19:36
Correct. The target manager itself has no parent.
– Sean Carey
Dec 30 '18 at 19:42
So that line of code makes no sense... ?
– Trt Trt
Dec 30 '18 at 19:43
No, the target manager has no parent. But we're not talking about the target manager. We're talking about the individual targets themselves. Those will be children of the target manager.
– Sean Carey
Dec 30 '18 at 19:45
1
In simple it just means thattarget
will be a child ofTargetManager
. It's a bit redundant though:target.transform.parent =...
would be enough ;)
– derHugo
Dec 30 '18 at 21:01
|
show 2 more comments
The target manager is just under the "SampleScene"... So it has no parent ?
– Trt Trt
Dec 30 '18 at 19:36
Correct. The target manager itself has no parent.
– Sean Carey
Dec 30 '18 at 19:42
So that line of code makes no sense... ?
– Trt Trt
Dec 30 '18 at 19:43
No, the target manager has no parent. But we're not talking about the target manager. We're talking about the individual targets themselves. Those will be children of the target manager.
– Sean Carey
Dec 30 '18 at 19:45
1
In simple it just means thattarget
will be a child ofTargetManager
. It's a bit redundant though:target.transform.parent =...
would be enough ;)
– derHugo
Dec 30 '18 at 21:01
The target manager is just under the "SampleScene"... So it has no parent ?
– Trt Trt
Dec 30 '18 at 19:36
The target manager is just under the "SampleScene"... So it has no parent ?
– Trt Trt
Dec 30 '18 at 19:36
Correct. The target manager itself has no parent.
– Sean Carey
Dec 30 '18 at 19:42
Correct. The target manager itself has no parent.
– Sean Carey
Dec 30 '18 at 19:42
So that line of code makes no sense... ?
– Trt Trt
Dec 30 '18 at 19:43
So that line of code makes no sense... ?
– Trt Trt
Dec 30 '18 at 19:43
No, the target manager has no parent. But we're not talking about the target manager. We're talking about the individual targets themselves. Those will be children of the target manager.
– Sean Carey
Dec 30 '18 at 19:45
No, the target manager has no parent. But we're not talking about the target manager. We're talking about the individual targets themselves. Those will be children of the target manager.
– Sean Carey
Dec 30 '18 at 19:45
1
1
In simple it just means that
target
will be a child of TargetManager
. It's a bit redundant though: target.transform.parent =...
would be enough ;)– derHugo
Dec 30 '18 at 21:01
In simple it just means that
target
will be a child of TargetManager
. It's a bit redundant though: target.transform.parent =...
would be enough ;)– derHugo
Dec 30 '18 at 21:01
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53977613%2fwhy-is-this-transform-set-in-this-unity-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
8kZ098a9kPlENWr wELTQpJ2i7AQviL3AT3