BlenderSleuth / FlyingNavSystemSupport

Support page for the Flying Navigation System
https://blendersleuth.github.io/FlyingNavSystemSite/
9 stars 3 forks source link

[Feature Request] Expose SetPreferredNavData() in C++ #4

Closed mostlyhuman closed 1 year ago

mostlyhuman commented 1 year ago

Hello there! Just purchased today and am still going through tutorials. I am trying to do as much setup in C++ as possible mainly so that I dont forget some of the steps once I am in blueprints, but as I was adding a FloatingPawnMovement to a Pawn derived class, i was surprised that the FloatingPawnMovement didnt have a way to set the preferred nav data like you do in blueprints. Would be quick and handy if that could be added at some point in the future. I realize there may be a technical reason I dont fully understand that makes it not possible but still wanted to reach out.. Thank you for any consideration! :)

BlenderSleuth commented 1 year ago

Hi there, I think you'll find that any movement component that derives from UNavMovementComponent (which includes FloatingPawn) will have a NavAgentProps field, which has the relevant PreferredNavData field and setter. Does that help?

mostlyhuman commented 1 year ago

Ohh okay maybe so. Ive spent a good half hour trying to find the right logic and syntax to set this up in C++. I don' typically ask but in this case could you show me how I would code it to pre-set to use FlyingNavigationData in C++? I could put the code in my Pawn derived NPCBase class, or the AIController derived NPCController class, whichever you think would make the most senses or is doable. I am really digging the plugin, thank you so much for creating it! :D

BlenderSleuth commented 1 year ago

The movement component resides on the pawn, so it's more convenient to put it there, but if it's an AI controller to be used across multiple flying pawns (or if it's a hybrid flying/walking agent) then putting this line in the controller might be the way to go. If you have a custom movement component for flying AIs you could even just put it in the component constructor.

This can be put into a constructor (which will be reflected in the editor), or in begin play. MovementComp->NavAgentProps.SetPreferredNavData(AFlyingNavigationData::StaticClass());

mostlyhuman commented 1 year ago

Welp... having an issue where my pawn wont move. i am following your quickstart and have looked over everything twice so I am not sure what I am missing. Here is a checklist of what I have verified:

1) Agent is setup in Engine->Navigation Settings, it is named and both Nav Data Class and Preferred Nav Data are set to FlyingNavigationData 2) Nav Mesh Bounds Volume is scaled across the level and the Navigation Data has been built, confirmed by draw mode and nav mode 'P' 3) Collision/Can Ever Affect Navigation is disabled on the pawn blueprint mesh component 4) New AI Controller is assigned to the pawn and has the correct nodes to initialize the blackboard and behavior tree (when I run the scene I can see the behavior tree is working, it hits Move To for a split second then goes back to Wait) 5) The pawn blueprint has a FloatingPawnMovement component and Preferred Nav Data is set to FlyingNavigationData

Here is a very scaled down project, hopefully you can spot the issue. I removed all my custom C++ classes to get it as barebones as possible and eliminate variables.

Link to project https://drive.google.com/file/d/1bL1i6Wg9wFIQ5tiMniYXjDuEmd0OKl_a/view?usp=sharing

Also, when using MovementComp->NavAgentProps.SetPreferredNavData(AFlyingNavigationData::StaticClass());
It couldnt find AFlyingNavigationData, I tried to include your FlyingNavigationData.h but couldnt figure out a path to the file that it would recognize. Thank you again for any help, I sincerely appreciate it!

mostlyhuman commented 1 year ago

just checkin to make sure you are alive and healthy and havent been taken by the Babadook 😂

BlenderSleuth commented 1 year ago

Hey, sorry I’m currently at Unreal Fest Gold Coast so I’ve been a bit busy. I’ll get back to you over the weekend

mostlyhuman commented 1 year ago

sounds good, Ben. Have fun and looking forward to hearing back from you.

BlenderSleuth commented 1 year ago

So I've had a look into it and I found that the function AAIController::BuildPathfindingQuery is failing because UNavigationSystemV1::GetNavDataForProps is not returning an agent for the given agent properties. I've realised I've been on this chase before with this GetNavDataForProps function returning the 'MainNavData', which is sometimes mysteriously null. The fix is to comply with the silly algorithm for choosing the main nav data, which is to set the Default Agent Name in project settings to either None or a valid agent name. Not Default, the default agent name 😂.

image

BlenderSleuth commented 1 year ago

As for accessing AFlyingNavigationData::StaticClass(), you just need to make sure you include "FlyingNavSystem" as a link dependency in your .build.cs:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "FlyingNavSystem" });

and just #include "FlyingNavigationData.h"

mostlyhuman commented 1 year ago

Awesome! Got everything working, hopefully I will be self-sufficient from here lol I saw you have a discord channel so if I need any more help I will post on there so the community can jump in when they are able. Thank you again for all of your help!