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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Trying to get a variable to identify

What I want to do is I want a door to open after someone enters a password into a widget I set up with blueprint. I created a C++ class to open the door which works and I am now trying to set up a if statement for it to open when a variable I created changes.

To make a variable I can access in both blueprint a c++ I followed this guide and my variable I created in gamemodebase c++ component now shows up in blueprint: https://wiki.unrealengine.com/Blueprints,_Creating_Variables_in_C%2B%2B_For_Use_In_BP

Now I am trying to introduce my variable into other .cpp files specifically the one that opens my door but the problem is its not Identifying. My suspicions are that I am missing #include.

Here is header file for my game mode: alt text

And here is my .cpp c++ component for the door;

![alt text][3]

And here is the variable working in blueprint am trying to have it so when this is set c++ class for my door will take note of it and open the door according to my if statement.

alt text

[3]: /storage/temp/236918-opengate-cpp.png

Product Version: UE 4.19
more ▼

asked Apr 09 '18 at 08:45 PM in C++ Programming

avatar image

12 2 4 7

avatar image HarryHighDef Apr 10 '18 at 09:15 AM

You see the get and cast you do in your BP code to set the variable. You'll have to make the equivalent get and cast to get the variable in c++.

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

1 answer: sort voted first

You need to do something like this:

ACemeteryFPSGameModeBase* CemeteryGameMode = Cast(UGamePlayStatics:GetGameMode(GetWorld()));

if(CemeteryGameMode->GateKey > 1) OpenGate();

more ▼

answered Apr 10 '18 at 11:05 AM

avatar image

375 2 8 13

avatar image HitmanRm95 Apr 10 '18 at 11:32 PM

I gave it a shot but "Cast" has a error "no instance overloaded function" & "UGamePlayStatics:" is coming up as "Identifier is undefined".

I was thinking I was missing a include for UGamePlayStatics so I included the following in my .cpp:

include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"

But it still appears as undefined. I am assuming I am missing some includes.

alt text

cpp-change.png (13.8 kB)
avatar image HitmanRm95 Apr 11 '18 at 10:40 AM

OK I fixed the issue with UGamePlaystatics by changing the capital P to a small p to get UGameplayStatics.

However the issue with cast is still present and Get World now has the following error: Uworld UActorComponent::GetWorld() const argument of type "UWorld " is incompatible with parameter type "const UObject"

alt text

cpp-change-2.png (12.5 kB)
avatar image Velrin Apr 11 '18 at 10:50 AM


Apologize for that, the example listed in my comment is incorrect. Initially I thought I wrote it incorrectly but it appears the forums here doesn't like a full cast example. Put your ACemeteryFPSGameModeBase between those symbols in the example below.

Use Cast(UGameplayStatistics::GetGameMode(GetWorld()));

avatar image HitmanRm95 Apr 15 '18 at 01:19 PM

Thanks it greatly appreciated, It works now. The door now opens after a user interacts with my blueprint made widget in my game.

(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