News › Forums › RAIN › General Discussion and Troubleshooting › How to Register NavigationTarget During Game
Tagged: GetNavigationTarget, NavigationManager
This topic contains 8 replies, has 2 voices, and was last updated by blockcipher 3 months ago.
-
AuthorPosts
-
April 28, 2022 at 8:50 am #40337
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.
April 30, 2022 at 12:04 pm #40339How 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.
May 1, 2022 at 9:20 am #40340Rig is not created at runtime. Once the user drag and drop image from GUI a GameObject is instantiated that has NavigationTarget child gameobject.
May 1, 2022 at 3:42 pm #40341I 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.
May 3, 2022 at 4:15 am #40344Thank 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 = ??
May 6, 2022 at 3:33 am #40360Any answer for this please…
May 7, 2022 at 12:11 am #40362Sorry 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(); }
May 9, 2022 at 3:09 am #40364Thank 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;
May 9, 2022 at 10:08 am #40370Very nice. Glad you got it working!
-
AuthorPosts
You must be logged in to reply to this topic.