Where do i put my game logic(as a whole)?
Hi guys. i have been doing LITTLE/FEW things in UE, like Youtube tutorials, reading many times the online documentations, experimenting with some things.Some time ago i was programming in Unity and decided to migrate to UE4. i know many languages, design patterns, software design and that stuff... so, that is my background. My problem here is this, i am struggling trying to figure out where to put my code(Blueprint or C++). I know there exist a GameMode, LevelBlueprint and the normal blueprints(a C++ class).
1- if i want my ship for example to move around and shoot something i can do that. But lets say i want to control how many ships spawns, where,when and how, Where should i put that code? should i create a new C++ class/Blueprint called like "MyShipSpawnLogic"?? Should i put that code in GameMode or Levelblueprint? i downloaded some project examples but those confused me more since they manage differently the blueprints.
2- If i create a class, then i add a variable INSTANCE of that class to my blueprint(not simply the class variable),that is supposed to create an object ready to go since the beggining of the game loop?
3- Does anyone know where can i find a more in-Depth documentation or paper about how the engine really works? i feel like i am not understanding how the main loop works(or what ever the engine works), or how the order of execution is regarding LevelBlueprints GameMode and my normal Blueprint/C++ classes :( I really hope to get any orientation or help you can give me, many thanks! :D
asked Apr 29 '15 at 06:03 PM in Blueprint Scripting
Here are the docs for the gameplay framework. This is the best explanation I've found of intended game logic organization:
This one is a great quick overview:
There are probably several ways you could get things to work, but some organizations are better than others. General game logic almost definitely shouldn't go in the level blueprint; the level blueprint should be for things that are specific only to that one level. Logic for spawning new enemy ships probably would go in a GameMode, Controller or Pawn, but I'm actually not totally sure myself. Take a look and see what you think.
It depends on what you mean by "variable instance of that class." If you're just creating a blueprint variable in the Variables section of the blueprint, then no, that won't actually spawn an actor. A variable just holds a reference to an already-spawned actor (or to nothing, which will be the default). If you know what pointers are in C++, it's the same thing. You have to either add the actor to a level in the editor from the content browser (static) and then get a reference to it in the blueprint, or programmatically spawn the actor in your blueprint using the SpawnActorFromClass node (dynamic). Does that make sense?
answered Apr 29 '15 at 07:40 PM
Regarding level blueprints, there are some subtleties here, and I can't quite tell if we're on the same page or not. The level blueprint should contain minimal core functionality, meaning you wouldn't want to put all the code for how to spawn ships there. If you have another class that defines how ships are spawned, though, instantiating that class in the level blueprint is fine. Or you could just make your ShipManager class an Actor and add it to the level through the content browser statically, so you wouldn't have any code in the level blueprint.
Regarding instancing, I'm confused -- is your "blueprint class" written in C++ or Blueprints? Because you list some C++ there.
Unless I'm misunderstanding you, that's not correct. That's not a class. The difference between a class and an instance object is that a class is the definition of a type of thing, and an instance is an an actual, real, concrete one of those things. What you have listed here isn't a class, it's a pointer to an instance which isn't instantiated yet. A class would be if you stored "EnemyShip" itself so you could know what kind of ship you want to spawn later. Blueprints give you the ability to create variables for both instances and classes, because sometimes you need one or the other.
Anyway, it depends on what's in your EnemyShip constructor, but this line will probably not spawn a new ship:
You don't need to use "new" for spawning actors in UE4, because UE4 has its own memory management. You need to use the SpawnActor method: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Actors/Spawning/index.html
Haha thanks again, i believe i am understanding this, and yes we are on the same page :D those C++ code was just an abstracted examples of classes and objects to understand how UE works, i know that i cant do that in UE couse it has others mechanism to spawn things :D (EnemyShip *myUninstantiatedShip; -> abstract example of a variable uninstatiated of the class EnemyShip, we are on the same page hahaha), i treat C++ classes and Blueprint classes in the same abstract way, as simple classes just to give you examples, then i will see how i use each one and their mechanism, I think you let me all the theory pretty clear :D i will code something and come back here then :D, Ey clt2488, Many thanks!
answered Apr 30 '15 at 10:00 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here