News Forums RAIN General Discussion and Troubleshooting How to Register NavigationTarget During Game

This topic contains 8 replies, has 2 voices, and was last updated by  blockcipher 3 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #40337

    Ibrahim
    Participant

    Hi,

    The function:

    NavigationManager.Instance.GetNavigationTarget("target_name");

    returns null. I found that the reason for this was that the player is placing the “target_name” during the game, so it is NOT registered by the NavigationManager. Do you have a solution for such a problem?

    I read in the API that registration is done during the AWAKE function. How can I register these new targets during the game?

    • This topic was modified 3 months, 1 week ago by  Ibrahim.
    #40339

    blockcipher
    Participant

    How are you creating the rig during runtime? Is it from a prefab or in code? I know you can use the NavigationTargetRig.CreateRig helper method which returns a new NTR. I assume it registers it also.

    #40340

    Ibrahim
    Participant

    Rig is not created at runtime. Once the user drag and drop image from GUI a GameObject is instantiated that has NavigationTarget child gameobject.

    #40341

    blockcipher
    Participant

    I remember someone having a similar issue with (I think) the Waypoint Route/Network when it was being created at runtime or from a placed prefab (including me). The process should be similar so I will mess with it when I get home and try to flesh it out.

    EDIT: Try a call to _MyNavigationTargetRig.Serialize() and see if that registers it correctly.

    • This reply was modified 3 months, 1 week ago by  blockcipher.
    #40344

    Ibrahim
    Participant

    Thank you for your reply, I searched the API and found it, but I do not know how to set a reference to it, maybe you can help me.

    NavigationTargetRig  _MyNavTarRig = ??
    #40360

    Ibrahim
    Participant

    Any answer for this please…

    #40362

    blockcipher
    Participant

    Sorry I have been very busy. Well you said your code places an instantiated prefab when a button is clicked so you would just grab the rig component from the prefab and call it that way.

    Such as

    void Start()
    {
      var m_navTargetRig = GetComponent<NavigationTargetRig>();
      m_navTargetRig.Serialize();
    }
    #40364

    Ibrahim
    Participant

    Thank you for your help.

    I found out that registering the navigation target is not what I needed to solve my problem. I found out that changing the name of the navigation target this way:

    instantiatedObject.transform.FindChild("my_nav_target").name = "nav_target_" + i;

    did not change the NavigationTarget, but only the mountPoint name. And this why my statement:

    NavigationManager.Instance.GetNavigationTarget("my_nav_target_" + i)

    returns NULL.

    The correct way to change the NavigationTarget name is:

    instantiatedObject.transform.FindChild("my_nav_target").GetComponent<NavigationTargetRig>().Target.TargetName = "nav_target_" + i;

    #40370

    blockcipher
    Participant

    Very nice. Glad you got it working!

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.