I am new to Unreal (switched from Unity) and still have some troubles understanding the main concepts, in this case how to access other objects and their components via c++ scriptig. I am using UE5 (but I guess solutions for UE4 should also work fine).
My Project looks as followed:
In my scene I have an "Target" Actor (Blueprintclass) that has a self written c++ "movement" component with some public function to update its position.
More over I have an "Experiment" BP Actor that has a "TrialProcedure" c++ component attached.
Here is what I want to do: I want to run the Target's movent component's update position function from this Actor's component.
I guess once I can access the Target Actor, I can use GetComponentByClass() to access the component I need and than run it's method. But how do I get access to that other actor without using blueprints? The Actor is already there so I don't want to spawn it from code.
Thanks in advance!
That is a sub-optimal solution. Use a collision and get the Other Actor, then try to cast it to your desired class if it's a collision event. If it fails, don't do anything but if it doesn't, pull a pin from that and execute your functions.
A better alternative to your current solution would be to use the Get All Actors of Class function if you only have a single target. Just use the Get (a copy) node and you'll have your target blueprint. There's a C++ version of the function as well. If you have more than one file, then you'll have to check stuff.
I'm going through the tutorial here, and am seeing that the create method on IotSupervisor is called and the result passed to ActorSystem in the root of the application. However, I was wondering why would this unused actor be used instead of DeviceManager, which is the top-most actor that interacts with its child actors.
Because both DeviceManager and DashboardManager will be IotSupervisor's children according to the diagram. That's why the application needs an entry point which lives in a higher level than DeviceManager.
Find the diagram below, I copy it from the exact tutorial link.
I'm currently working on a little project in C++. I'm fairly new to C++/Programming and wanted to ask how my classes should be designed.
To be specific: I want to write a little program for chatting. Just simple communication between two programs/computers. For that I want to use a good class design because, although it is only a small project (just for the sake of learning), I want it to be well designed and extensible.
My program should have about 5 classes (Handlers etc, the Updater and App - the main class only for this program).
I'll give you a few examples of ideas I have how I could design one part of the program. The first part should be the connection part (handled by Connection). The task is to build up a connection between the two programs. It will also set up local files, which will hold the information to print, and connect it to the 'server' file. Later in the program there should be access to the File_Handler class so it can edit/read the local file and read/request to write to the 'server' file. (How exactly it's gonna do it is already figured out, so as long as it is not necessary I'd like to keep this system as it is ;) ). But now let's get to the ideas I have:
Idea 1
App creates an instance of Connection to set up the connection.
Connection then creates an instance of File_Handler which will set up the files (in this case File_Hanlder would hold the paths with static variables) and then destroy that instance because it is no longer needed by Connection.
Another class (instance is held by App) then creats an own instance of File_Hanlder later and could work with the files since the variable for the path is static.
Idea 2
App creates an Instance of Connection and File_Handler (lets call them con and fil).
To set up the connection, fil is passed per reference to con to set up the variable paths for the files and create the files etc. .
For working with the files later, App would pass around fil to manage all the file handling for the other classes which would, for example, update the chat etc.
That would require a lot of classes to have a constructor or (a) function(s) which needs to have a File_Handler parameter and the same variable would be passed around a lot of times.
Idea 3
The last idea I have is that Connection, File_Handler and the other classes would be created very general without any or near to zero relation to other classes.
App then creates a lot of functions (or even 'subclasses') to work with these classes almost like working with Frameworks which were developed independently and thus could, theoraticly, be used in another program without any problems.
Which solution do you think would be the best? Or is there another solution you have for me which would be even better?
I am currently developing a Maya plug-in in cpp. From the main class, I create a custom node instance (MPxLocatorNode) using the MDagModifier createNode command. However, how can I pass information (a bunch of floats) to this custom node so that it takes them into account and acts upon it ?I believe the plugs will help me, but I have no clue where to start: In the main class, how to link a plug to the instance and in the instance how to receive the plugs knowing that compute doesn't seem to be used as the instance does not have any input.Thanks.
I've been having an issue with the basic structure of a program that I'm working on. I'm a very inexperienced programmer trying to teach myself the basics of programs that use multiple states.
Right now, I have a very simple game-ish program with a game loop that redirects event, logic, and rendering to my StateManager class, which pushes and pops states onto a . The StateManager class then redirects the events, logic, and rendering to whatever state is on the back() of the vector. The idea is to have an assortment of different states for each phase of the program (in this case a simple game with splash screens, menus, gameplay, death screens, etc)...
However, I'm a VERY novice coder (trying my best to learn), and I've run into a fundamental issue with my program right from the very first state class...
The first class that I made is the SplashScreenState. And the basic concept was to have a state that essentially just shows a series of 'splash screen images' (lets say 3, for the sake of example), and each time the user presses a key, it switches to the next image, and finally (when it is out of splash screen images to cycle through) switches to the next state (menustate).
My problem is that I'm having a hard time figuring out how to structure this. Originally, I made the mistake of treating each different splash screen image as an instance of the SplashScreenState. However, I figured that do so was incorrect, as all 3 splash screens would technically be part of the same 'state'.
So now I have two main issues:
The first issue is that I'm not sure how/where to store all the splashscreen images. If I want to cycle between 3 different screen images when the program starts up, should I make them all members of the SplashScreenState class? Or is it smarter to simply have one class member for the 'currentImage', and each time the user hits a key it runs a load() function to load the next image into the currentImage pointer? Is it better to make an array or vector of images and cycle through them? I'm just not sure...
My second issue is with the eventhandling() of the SplashScreenState.. I know that I want the image on the screen to change like; *image1 -> image 2 -> image 3 -> changeState(menuState).. So that each time the user hits a key on their keyboard, it switches to the next splash screen, until the last splash screen, where it will then change state to the main menu. I'm not sure what the best way of doing this is either.. Should I create an enum for each splash screen and increment through them (until the final screen where it changes states)? I also think that, if I did store all my various screens in an array, then I could easily increment through them, but then would that be unoptimized because all the screens would have to be stored in memory at all times?
Anyway, I'm know this question might be very basic and noobish, but that's where I am right now unfortunately! I haven't had any formal education in programming and I've been teaching myself, so I really really appreciate all the help and expertise that's present on this site! ^^
Thanks!
You seem to be torn between an object-oriented vs a procedural paradigm for handling state transitions. The other answer suggesting a switch statement to handle enumerated state changes is a good procedural way to go about it. The drawbacks to that are that you might end up with a monolithic game class that contains all the code and all the superfluous state-specific data for handling your event/logic/rendering for all possible states. The object-oriented way to handle this is much cleaner, and encapsulates these into their own separate state objects where they can be used polymorphically through a shared interface. Then, instead of holding all the details for handling all the states in your game class, your game class needs only to store a state pointer and not worry about the implementation details of the concrete state object. This moves the responsibility of handling state transitions out of the game class and into the state class where it belongs. You should read up on the state/strategy pattern from a design patterns book. Handling the changing of a state should be the responsibility of the state object itself. Here is some reading:
http://www.codeproject.com/Articles/14325/Understanding-State-Pattern-in-C
http://sourcemaking.com/design_patterns/state
http://sourcemaking.com/design_patterns/state/cpp/1
http://codewrangler.home.comcast.net/~codewrangler/tech_info/patterns_code.html#State
http://en.wikipedia.org/wiki/State_pattern
http://www.codeproject.com/Articles/38962/State-Design-Pattern
Quoting from the Design Patterns and Pattern-Oriented Software Architecture books:
The pattern-based approach uses code instead of data structures to specify state transitions, but does a good job of accommodating state transition actions. The state pattern doesn't specify where the state transitions must be defined. It can be done in the context object, or in each individual derived state class. It is generally more flexible and appropriate to let the state subclasses specify their successor state and when to make the transition.
You have the option of creating state objects ahead of time and never destroying them, which can be good when state changes occur rapidly and you want to avoid destroying states that might be needed again shortly. On the other hand, it can be inconvenient because the context must keep references to all states that might be entered.
When the states that will be entered are not known at run-time and contexts change state infrequently, it is preferable to create state objects as needed and destroy them thereafter. In determining which to use, you need to consider cost as well as transition frequency.
Excellent explanation of your problem, first of all.
The portion of your game managing the splash screen can work in two ways. You've examined the problem and it's really that simple:
Receive input; set next state.
So, examples:
STATE_SPLASH1
STATE_SPLASH2
STATE_SPLASH3
STATE_TITLE
STATE_GAME_INIT
STATE_GAME
STATE_EXIT
pseudocode:
state = STATE_SPLASH1
while (state != STATE_EXIT)
... receive input ...
... process events to responders ...
... update ...
... yadda yadda ...
switch (state) {
case STATE_SPLASH1:
show_splash1()
case STATE_SPLASH2:
show_splash2()
case ..:
case STATE_TITLE:
show_title()
case STATE_GAME_INIT:
show_loading()
setup_level()
setup_characters()
case STATE_GAME:
game_update()
case STATE_EXIT:
cleanup_and_quit()
Another way is to manage splash a 'game state' and then the state of the splash as an internal state. and when splash has no more logic to run, set the game state to the next one. When I was learning, I found the DOOM source to be a valuable resource and man, is it nothing but hundreds of state machines. :)