question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in WorldAnchorManager.AttachAnchor method

See original GitHub issue

According to the documentation of the AttachAnchor(GameObject gameObjectToAnchor, string anchorName = null) method, you can provide an anchor name or leave it empty. In case you leave it empty, the method uses the name of the GameObject. The documentation of the parameter anchorName says, the name is a generated GUID.

<summary>
Attaches an anchor to the GameObject.  
If the anchor store has an anchor with the specified name it will load the anchor, 
otherwise a new anchor will be saved under the specified name.  
If no anchor name is provided, the name of the anchor will be the same as the GameObject.
</summary>
<param name="gameObjectToAnchor">The GameObject to attach the anchor to.</param>
<param name="anchorName">Name of the anchor.  If none provided a GUID is generated for you.</param>
<returns>The name of the newly attached anchor.</returns>

Right now, the framework overwrites my custom name and sets the gameObject name instead. The reason for this is the conditional being wrong. Instead of this: anchorName = string.IsNullOrEmpty(anchorName) ? anchorName : gameObjectToAnchor.name;

it should be like this: anchorName = string.IsNullOrEmpty(anchorName) ? gameObjectToAnchor.name : anchorName;

I will try to fix this myself or call for help if I can’t get it running. This means that I will go with the GameObject name, instead of the GUID and update the XML Documentation.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Zod-commented, Oct 4, 2017

@eluchsinger There is no need to import anything. NUnit is already included with Unity. Just create a new class and add tags to test methods and then you can run it from the Test Runner window in the Unity Editor. In the Editor, you can also create a template file using Create > Testing > EditMode Test C# Script.

For this particular method, you’ll have to extract that logic into a separate method since it won’t run in the editor e.g.:

public static string GenerateAnchorName(GameObject gameObjectToAnchor, string anchorName = null)
{
    return string.IsNullOrEmpty(anchorName) ? gameObjectToAnchor.name : anchorName;
}

And then test it.

public class WorldAnchorManagerTests
{
    [Test]
    public void TestGenerateAnchorNameFromGameObject()
    {
        const string expected = "AnchorName";
        var gameObject = new GameObject(expected);
        var result = WorldAnchorManager.GenerateAnchorName(gameObject);
        Assert.That(result, Is.EqualTo(expected));
    }

    [Test]
    public void TestGenerateAnchorNameFromParameter()
    {
        const string expected = "AnchorName";
        var gameObject = new GameObject();
        var result = WorldAnchorManager.GenerateAnchorName(gameObject, expected);
        Assert.That(result, Is.EqualTo(expected));
    }
}

image

0reactions
eluchsingercommented, Oct 4, 2017

@Zod- I would still be interested in knowing if I can add Unit Tests for this case, if possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ARAnchor is destroyed but still trying to access it. - ...
Bug MissingReferenceException : ARAnchor is destroyed but still trying to ... Using AR Foundation 4.1.1 and calling the method "Object.
Read more >
Development of an Augmented Reality Testing Platform for ...
This method uses a dynamic simulation that is built into Unity. This is called the physics engine. This engine takes the joint location...
Read more >
KEKUATAN AUGMENTED
Dalam contoh berikut, anchorManager merujuk ke Script WorldAnchorManager: anchorManager.AttachAnchor(gameObject, SavedAnchorFriendlyName);.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found