[Unity to Unreal] Losing world references

Hello,

Im transitioning from Unity to Unreal for a project but i’m having trouble understanding how the maps/world get’s handled by the engine.
In Unity i could create ‘blueprints/prefabs’ in the scene and store local references. But it seems Unreal reloads the map and spawns all my actors, losing any references stored.

Whats the best approach to setting up my scenes?

I’m trying to achieve some simple things:

  1. pick up items and store if i have them
  2. enter a trigger and have an event/animation occur
  3. a system using a list of nodes to represent waypoints so i can guide the player where to go next using particles/pathfinding. (problem here is how do i store the list of nodes. public TArray on a UWorld class?)

Any pointers would help out. a Uworld class doesnt get ‘spawned’ right?

Hey ,

Have you seen the Unreal Engine for Unity Developers guide? It provides a really good starting point for those coming from a Unity background.

Just a little bit of background. A scene is called a level in Unreal. Each time a level is loaded, a Game Mode is created. The Game Mode essentially specifies the rules and logic for the game, and the type of Game Mode that gets created is either determined by the default in the Project Settings or overridden in the World Settings for the level.

The Game Mode doesn’t persist across level loads so you can’t store anything on that if it needs to persist. In situations like that, there is a Game Instance that does persist across level loads which you could potentially store data on. Another option, of course, is to save that data out and load it back in.

For the trigger playing an Animation, would it be playing an animation on the player who entered it or on some other object or on itself? Either way, a Blueprint Class with a shape component should be able to detect an overlap and then you can play the animation using the OnOverlapBegin event.

Does the path navigation have to be done using path nodes? Unreal has navigation mesh support built in. You can create logic to move the player using those in code or in Blueprints, and you can also use that combined with Behavior Trees to do more complex navigation. More infor on that is available here: https://docs.unrealengine.com/latest/INT/Gameplay/AI/index.html

If you do want to store a list of nodes, a TArray is going to be the way to go. It’s like a List in C#. You could probably store them in your Game Mode class as long as that data doesn’t need to be replicated over the network. If replication is needed, using the Game State is another option. That’s basically the replicated part of the Game Mode.

I would love to try to help more if you can provide more info on what it is you want to accomplish. :slight_smile:

  1. This is STATE information, so that would go into a state object. You’ve got two to choose from: PlayerState and GameState. I’d probably put it in the player state.

  2. This can easily be done with blueprints. You can have the trigger area fire and event which triggers a blueprint script which creates an animation. There’s a bunch of tutorials online, and even better, there is a content examples project which demonstrates this and much more. Use that as your starting point :slight_smile:

  3. I think this would also be something which I’d store as a TArray of Vectors within the PlayerState class.

Dear ,

I have 3 types of solutions for you, based on your actual game needs, each with its own wiki for more code and details!

Solution 1 ~ The Level Blueprint

If you are placing objects in the world using the editor, the fastest way to modify/track these objects is using the Level Blueprint!

Blueprints->Level Blueprint, top middle button of main UE4 viewport

Then you select the actors in the scene, and then go into the Level BP and right click, you’ll see an option to get a reference to your actors!

Then you can do whatever you want with them!

You can make your own C++ Level BP to then use in the Editor and store your own C++ accessible variables!

Wiki on Creating Custom Level Blueprint C++ Classes
https://wiki.unrealengine.com/Solus_C%2B%2B_Tutorials#Solus_C.2B.2B_Tutorial:_Creating_Custom_Level_Blueprints_in_C.2B.2B


**Solution 2 ~ Game Instance**

If  you want to store data between levels, you should consider the Game Instance Class!

The Game Instance class is the best place to store data that you want to persistent between levels / from the time the game viewport is first opened till the user stops playing your game, even after many level changes.

**Wiki on Making a Custom Game Instance Class**
https://wiki.unrealengine.com/Game_Instance,_Custom_Game_Instance_For_Inter-Level_Persistent_Data_Storage


Solution 3 ~ Core Game Classes For Storing Dynamically Created Objects

If you are just wanting to store data like the TArray of points you mentioned, you should use one of the following core classes as a good starting point

Player Controller
Character
Player State
Game State

All four of these are replicated actors that exist on all client machines and support network functions.

Player Controller and Character support RPCs so that clients can send data back to the server.

I’d recommend Game State or Player Controller for your TArray of path points.

You’d create variables in a custom Player Controller or Game State Class.

In the wiki below I explain how to then create a BP of your Player Controller or Game State class and link them into your project so that they get used instead of the default engine classes.

Wiki on Custom Player Controller Class
https://wiki.unrealengine.com/Game_Mode,_Linking_to_Player_Controller_Blueprint


Enjoy!

**Welcome to UE4!**

[FONT=Comic Sans MS]♥

Rama

Wow guys, awesome support here! I’m very impressed with this community already.

Thanks so much!

@: I’ve followed the guide but it’s more of a glossary on what translated to what. I doesn’t educate on the engine flow. The fact a map get’s reloaded and actors get respawned is a bit of a mind bender coming from unity where reference are maintained a bit simpler in a scene. I found a handy link describing the libraries available (that i should know) and discovered the TArray which is how i figured i’d store the nodes, yes.

@Slayemin: isn’t a Vector a collection in itself? Or are we talking about a world position?

@Rama: We’ve tried solution 3. We have a character with a c++ class that has a public TArray node list in it. This is accessible from a blueprint. But when i try to assign a reference i get the following error:

If you download the source code from GitHub, you can look up the implementation of an FVector here:

(your actual path will vary)
C:\Users\Eric\Documents\Visual Studio 2013\Projects\UnrealEngine\Engine\Source\Runtime\Core\Public\Math\Vector.h

The implementation of it is a struct which contains X, Y and Z values and comes with a bunch of constructors, overloaded operators, and methods to do most common mathematical operations you’d want to do on a vector.

The TArray<T> is a templated collection of objects and behaves very similarly to a C# list or a C++ STL vector – which may be where you’re getting the terminology confused.