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"

I am having an issue with my projectiles not appearing

I am having an issue with my game, the projectiles being very buggy only spawn in certain areas of the map and the issue is ONLY when I use this new PlayerControlller class. I am not sure what the issue is in this script. If anyone can help identify the issue I would appreciate it.

I added the functions in to act as a cheat code to spawn an actor when a string was typed by the player.

Here are the files.

 // Fill out your copyright notice in the Description page of Project Settings.
 #pragma once
 #include "CoreMinimal.h"
 #include "GameFramework/PlayerController.h"
 #include "FPSPlayerController.generated.h"
 class FPSGAME_API AFPSPlayerController : public APlayerController
         void OnMissionCompleted(APawn* InstigatorPawn, bool bIsMissionSuccess);
         virtual bool InputKey(FKey Key, EInputEvent EventType, float AmountDepressed, bool bGamepad) override;
     FString CodeSequence;
     float TimeOfLastKeyPress;
     void ResetExpiredCodeSequence();
     void CheckCodeSequence();

And the CPP is below

 // Fill out your copyright notice in the Description page of Project Settings.
 #include "FPSPlayerController.h"
 #include "FPSBlackHole.h"
 #include "Engine/World.h"
 bool AFPSPlayerController::InputKey(FKey Key, EInputEvent EventType, float AmountDepressed, bool bGamepad)
     Super::InputKey(Key, EventType, AmountDepressed, bGamepad);
          // Only bother with presses (not releases) and don't worry about mouse button events
      if (EventType == EInputEvent::IE_Pressed && Key.IsMouseButton() == false)
          // Clear the CodeSequence string if the last key press was more than 2 seconds ago
          ResetExpiredCodeSequence();  // in case it's not clear, this is another custom function
          // float TimeOfLastKeyPress is a float variable that you'll also set up in your Player Controller class
          TimeOfLastKeyPress = GetGameTimeSinceCreation();  // set the time (now) for the current key press; this is used by ResetExpiredCodeSequence(), above
          // Add the pressed key's "character" to the CodeSequence (by getting the key's string representation)
          CodeSequence += Key.ToString();
          // Call a custom function that compares the sequence to a list of your matching 'codes'
      // Return a bool by calling the Super version of this function
      return Super::InputKey(Key, EventType, AmountDepressed, bGamepad);
 void AFPSPlayerController::ResetExpiredCodeSequence()
     // Find out how many seconds has passed since the last key press
     float TimeSinceLastKeyPress = GetGameTimeSinceCreation() - TimeOfLastKeyPress;
     bool bSequenceExpired = TimeSinceLastKeyPress > 2.0f;  // arbitrarily choosing 2 seconds for this example
     if (bSequenceExpired)
         // If more than 2 seconds has passed since the last key press, reset the string; otherwise, don't do anything
         CodeSequence = "";    // reset the string back to a blank, empty string
 void AFPSPlayerController::CheckCodeSequence()
     if (CodeSequence == "E")
         UE_LOG(LogTemp, Warning, TEXT("Wokrkinge"));
     else if (CodeSequence == "EXAMPLE2")
         // Just another example to show that you can handle more than one match possibility
     // etc.

Product Version: UE 4.21
more ▼

asked May 02 '19 at 02:58 AM in C++ Programming

avatar image

10 2 3

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

1 answer: sort voted first

There isn't really anything in that which would cause the behaviour you described. The one error that I can see at a glance is that you call Super::InputKey twice. You probably only need this once.

Does this script run as you'd expect (i.e. does it print out Wokrkinge) when you press E?

One other thing to note (which might be intentional) is that if you start typing 'EXAMPLE2', you'll first hit the 'has E been typed' condition. When it's just priting to the log that's fine, but if it's performing something more complex you might end up trying to trigger one action on top of another.

more ▼

answered May 03 '19 at 12:05 PM

avatar image

1.5k 6 6 12

avatar image Craggyy May 03 '19 at 03:03 PM

Yeah it was the super twice, didn't realize that would cause an issue with the projectiles. Thanks man

avatar image phil_me_up May 03 '19 at 04:45 PM

Glad it helped. I converted this into an answer. Can you mark it as accepted to help others find their answers too.

(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