UE4 c++ and blueprint share input - c++

Im trying to make a game and used a bit of c++ for a grabber and open door function where I bind in both of them the e key called Interaction to theyr respective usage, now im trying to make a dialog box and had to use some blueprint and linked the e button, the same as before to the show ui function but whenever I bind it and start the game my other two c++ bind don't won't work and when the dialog one is deactivated my two c++ one will work. So yeah I was wondering how could I use blueprint and c++ at the same time on the same keybind. I tried for the moment to create a new input on the same key and the [roblem persist and I cannot find any usefull information on the net.

In nutshell, APlayerController::PushInputComponent(UInputComponent InputComponent), this method will help register your Actor, Widget or anything you want to bind input event.
So it is OK that bind same key to multiple Actors' behavior, but you need concern that this KEY will be consumed in default, in your case, after construction of UInputComponent, while bind action, you may set InputComponent->BindAction(…).bConsumeInput = false.
This flag indicates that if delegate calling will consume this key, so lower priority input component is still eligible to trigger.

Related

C++ application: Passing a value from a form to the main window private variable

I am developing an application to feed a database. My main window is basically a menu that opens forms for different utilities.
Not sure if it's the best practice but let me explain what I'm trying to do:
my class mainwindow has a private QString that will store the current project name. In the menu, "Load" opens the form (another class) that lists all the existing projects in a combobox. The user chooses the project he wants and clicks OK.
I would like to return the combobox.currentText() into the dedicated private variable. After some research I still cannot figure out how to make it, wether I should use SIGNAL from the form to trigger a SLOT of the mainform or if there is a simple way to just return a value after pressing OK (such as an input dialog). If i am not clear enough, maybe the following sketch could help.
I definitively have a lack of knowledge on the subject but would be grateful for some help.
Indeed if your form for loading a project would emit a signal currentProjectChanged as soon as the user accepts the form (presses the OK button), this signal could be connected to a slot of the main window. For simple things this may be fine and elegant.
On the other hand reacting on actions sometimes needs more logic. If your action triggers a slot that cares for action execution, this slot probably should implement the logic. It should open the form and check whether the user has accepted the project change (pressed OK). In this case the action execution slot could get the new project name from the form and call a main window method to pass the new project name.

Raycasting from player, hitting object and setting off custom event C++ UE4

I've been going in circles for a day now trying to get this going and I'm just getting nowhere. I'm trying to have multiple objects in the scene with individual animations and when I fire a raycast from my player and it hits one, have the UFunction(blueprintimplementableevent) go off on the object that it hits. Please help me this is absolutely stumping me.
What I would do is use a BlueprintNativeEvent. This will allow you to create an Implementation function of the stuff you want to happen in C++, as well as a blueprint implementation, which can be different for each blueprint of that object type.
It is quite simple to use as well, for example, in your character's header file:
/** Called when the player presses the fire key */
UFUNCTION(BlueprintNativeEvent, Category = "Shooting")
void OnHit();
virtual void OnHit_Implementation();
And now your Cpp:
void AMyGameCharacter::OnHit_Implementation()
{
UE_LOG(LogTemp, Warning, TEXT("OnHit_Implementation!"));
// Do whatever stuff you want to do in C++ here
}
Now over in your character / actor blueprint, just go to the event graph, right click, and add the event of type OnHit. Make sure that you make a callback to the parent OnHit event though (right click on the event and hit "Add Call to Parent Function")
If you want an example of this you can look at the C++ Battery Collector series or the docs.

Qt/QML: Delay window rendering until data is available

I am building an application using Qt/QML. The QML of my main window is very complex and depends on lots of data which must be loaded via HTTP and then be processed by a C++ backend before it is ready to be displayed.
The C++ backend provides a signal which is fired when the data is ready. Until then, I want the window to be empty except for a simple loading indicator being displayed. Of course, I could use a simple overlay which hides my actual interface until the data is available, but this would mean that the QML code of my actual user interface is already loaded and tries to access the not-yet-available data, which is causing a lot of errors, so I would need to add dozens of dummy values and NOTIFY signals for each single property which might not yet be available.
What is the best way to completely deactivate a portion of QML code and to enable it as soon as a signal is triggered?
My personal experience is to not give data to your view components, don't bind them. For example, set your text value to an empty string or don't set it, set your image component source to an empty string or don't set it at first. When your signal comes in with data ready, you assign the data to the views at that time.

TObject.Show() not reachable on C++ Builder

I'm currently starting to learn how to use C++ Builder. However, I'm stuck on doing something basic, which is to open a window when I click on an element of the menu. I'm ok with the event management, but when I try to display it with the method Show(), it's written when compiling that "the method is not reachable" (I have it in french so I'm not sure about the exact translation). I've tried it different ways, also with the popup element, but I always get this message. Here is the short code that I use to display the window :
TFrame1 * NewPageFormer = new TFrame1(this);
NewPageFormer->Show();
delete NewPageFormer;
NewPageFormer = NULL;
Do you have any idea where the problem comes from?
Thank you
Try with:
TForm1 * NewPageFormer = new TForm1(this);
NewPageFormer->Show();
What you should Show() is a TForm (e.g. take a look at How do I open a new form with a button, using C++ Builder?).
Frames are combinations of components placed on a form-like object, which are considered a cohesive whole.
A frame (TFrame), like a form, is a container for other components. It uses the same ownership mechanism as forms for automatic instantiation and destruction of the components on it, and the same parent-child relationships for synchronization of component properties.
However a frame is more like a customized component than a form, so you cannot directly call the Show() method of a frame.

ATL COM: Function to Return when Callback has been Executed

Background:
I'm implementing a COM interface to an existing legacy C++ MFC application. The application is multi-threaded using one thread (main thread) for COM / GUI and one for incoming events from a C-library. The COM interface reflects the possible interactions the user can do using the GUI.
Edit: The COM server is "out-of-process" i.e. COM is implemented by the MFC application.
Problem description:
The COM interface has a function to select an object in a tree-view controller. When an object is selected the user can call COM functions that will use the object to execute different functionality.
Example 1 - What the user see / feel:
Object X is selected in the tree-view using function Y from the COM interface.
X is highlighted in the GUI and function Y returns.
User calls Function Z that will delete object X.
The MFC application is written such that the model many times is tightly coupled with the GUI callback functions for various reasons. For the SelectObject function this means that the object isn't truly selected in the tree-view until a callback function has been fully executed. This means that Example 1 in reality look more like:
Example 2 - What really happens:
Object X is selected in the tree-view using function Y from the COM interface.
Function Y set object X to be selected and Y returns.
A callback function (could be OnSelChanged()) for the tree-view item is called and update all the GUI elements and application model to select X.
User calls Function Z that will delete object X.
This isn't a problem for the user if when normal GUI interaction is used; the callback function is called in a very short amount of time after the user select object X in the tree-view so function Z will remove object X.
When using the COM interface this becomes a problem. When function Y returns the user can chose to immediately call function Z. If the callback function has been called object X will be deleted, otherwise an unexpected behavior will occur.
This is unwanted behavior. A function like SelectObject indicates to the user that when the function has finished executing, an object should be selected without any extra wait.
Solution ideas
I have been trying to figure out solutions to this problem and came up with some possible ideas:
Send event when the callback has finished
This is unwanted because I still think that when function SelectObject is done executing the user should expect object X to be selected, the user shouldn't have to wait.
Rewrite and separate the GUI and model.
Very much something I would like, but there's not time for that. The way the GUI is updated is very much coupled with everything else in the application and would require huge changes.
Have COM and GUI running on a separate thread.
This one is interesting. I don't know if it's possible; I haven't found any information that such a separation is possible. It seems COM is locked to work on the main thread only.
Number 3 is interesting but I lack the knowledge. Has anyone had any similar problem that they solved? I would really like some help with this problem :)