x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Spawn bot with player state? - 4.17

I am trying to create a FPS game with bots (similar to shooter game example). I want the bots to behave just like other players, so I want them to have a player state to keep scores, names, team, etc.

I have not found a way to do this in blueprints. I stumbled upon a post showing how to do this in C++ (https://answers.unrealengine.com/questions/62160/blueprint-do-aicontrollers-characters-have-players.html), but it was for version 4.4 (I think). I know almost nothing about C++, so I do not know how to do it in version 4.17, which is what I am using.

Does anyone know what the updated code would look like? Thanks.

Product Version: UE 4.17
Tags:
more ▼

asked Nov 04 '17 at 08:51 PM in Blueprint Scripting

avatar image

DJV
1 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Figured this one out on my own. For anyone else with this question, here is what I did (again, this is Unreal Engine 4.17):

I created a C++ class. I named it BotAIController. It's parent class is AIController.

In the .cpp file:

 #include "BotAIController.h"
 
 
 // Function that sets bWantsPlayerState.  bWantsPlayerState is a variable in the parent
 void ABotAIController::SetWantsPlayerState(bool NewValue)
 {
     bWantsPlayerState = NewValue;
 }

In the .h file:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "AIController.h"
 #include "BotAIController.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class SPECVS_MK3_API ABotAIController : public AAIController
 {
     GENERATED_BODY()
     
 public:
 
 // Sets the variable bWantsPlayerState
     UFUNCTION(BlueprintCallable, Category = "PlayerState")
     void SetWantsPlayerState(bool NewValue);
 
 };

Remember, if you name your project or controller something different, you will have to make some minor changes to the code.

That's it! It was much more simple than the code for 4.4, which, for anyone interested, looked something like this:

.cpp file:

 #include "BotAIController.h"
 
 
 
 ABotAIController::ABotAIController(const class FObjectInitializer& ObjectInitializer)
 : Super(ObjectInitializer)
 {
     bWantsPlayerState = 1;
 }
 

.h file:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "AIController.h"
 #include "BotAIController.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class SPECVS_MK3_API ABotAIController : public AAIController
 {
     GENERATED_BODY()
     
 public:
 
     ABotAIController(const FObjectInitializer& ObjectInitializer);
 
 };
 


more ▼

answered Nov 05 '17 at 03:31 AM

avatar image

DJV
1 2 2

avatar image DJV Nov 05 '17 at 05:08 PM

One thing I forgot to mention is that you also need to create a Blueprint. Right-click on your C++ class and click 'create blueprint based on class'. Open the new blueprint, and in the construction script add the node 'Set Wants Player State' (the new function created in C++). Check the box called 'NewValue', and then it should work.

Cheers!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question