x

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. 

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

Product Version: Not Selected
Tags:
more ▼

asked Apr 29 '15 at 06:03 PM in Blueprint Scripting

avatar image

The Argentine
41 4 8 9

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

3 answers: sort voted first

1- lets say i want to control how many ships spawns, where,when and how, Where should i put that code?

Here are the docs for the gameplay framework. This is the best explanation I've found of intended game logic organization:

https://docs.unrealengine.com/latest/INT/Gameplay/index.html

This one is a great quick overview:

https://docs.unrealengine.com/latest/INT/Gameplay/Framework/index.html

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.

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?

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?

more ▼

answered Apr 29 '15 at 07:40 PM

avatar image

clt2488
270 17 35 37

avatar image The Argentine Apr 30 '15 at 01:59 AM

Ey clt2488 ! THANKS for your time! i already readed those URL you said, but those arent really clear for me :( what exactly a level blueprint is? From the documentation: "A Level Blueprint is a specialized type of Blueprint that acts as a level-wide global event graph. Each level in your project has its own Level Blueprint created by default that can be edited within the Unreal Editor, however new Level Blueprints cannot be created through the editor interface" but you said "General game logic almost definitely shouldn't go in the level blueprint" (i thought the same than you)

To me,reading the definition, a LevelBlueprint is a class that manages what happen in the world, manages when and why and how and where to spawn enemies,ships or other type of game logic. But i am not sure at all becouse of the GameMode Definition.

Lets say i have a blueprint/C++ Class created of a ship. But i have a Ship handler class that manages ships in the world. i would open Level blueprint, create an instance of the ShipManager and trough that i would instantiate a ship.. is that correct? from this perspective, Level blueprint is like the Main function of that specific level.

About the question 2, if a have a class/blueprint i can add a variable, that variable can be a class or a Instance: Class example would be: EnemyShip myUninstantiatedShip; //the variable value is null or garbage. Instance example: EnemyShip myInstantiatedShip= new EnemyShip(); //the variable is different from null or garbage. Going back to my question.. if i add a Instance variable to my blueprint class. when i instantiate the class, the variable will ve different than null(AKA will exist and be instantiated) is that true?

Many thanks for helping me to understand those tricky things. i am a programmer to the core and dont really like the blueprint matter, i have to learn it forced :P

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

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.

Class example would be: EnemyShip *myUninstantiatedShip;

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:

 EnemyShip *myInstantiatedShip= new EnemyShip();

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

more ▼

answered Apr 30 '15 at 05:20 PM

avatar image

clt2488
270 17 35 37

avatar image The Argentine Apr 30 '15 at 10:01 PM

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!

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

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!

more ▼

answered Apr 30 '15 at 10:00 PM

avatar image

The Argentine
41 4 8 9

(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