So we’re trying to create a system that allows users to search through every object, including those in levels that aren’t being streamed yet. To do this, I’m trying to create a database of objects at startup that can then be searched. My question is, is there a way to stream a level in from C++? This would mean I could stream each level in, get all the objects in it, unstream it, then stream the next etc.
Alternatively, does anyone know of a way I can just access unstreamed levels?
In the editor all streaming levels will be loaded, so in theory you could save off some kind of manifest or list of information in to your persistent level indicating where each actor could be found. That said, there is nothing to stop a sublevel from being opened and edited on its own, so there is no guarantee that it would remain accurate.
If you want to manually force each level to be loaded you could use the UGameplayStatics::LoadStreamLevel function, just as it would be used from blueprints to load each level, pull the information out of it you want and then call the UnloadStreamLevel function.
That’s exactly what I was looking for, thanks Marc!
#Writing Out Binary Files
You should look up Archive.h and ArchiveBase.h
you can write out to file a list of all objects and their values for all levels
and then each level can access this database from hard disk, and also update its contents
it is written out to a binary file that goes into a file of your choosing the user’s harddrive
sort of like a local user profile
UE4 already supports serialization of most data types and objects using the << operator.
I’ve used this system as the foundation for the saving and loading of my levels in my in-game editor where the user creates the level during runtime.
Archive and ArchiveBase classes are your friends!!
I recommend using the FBufferArchive, it is a binary array (TArray) as well as being an Archive (multiple inheritance)
I use FMemoryReader to get contents back out of the archive saved to disk
You can compress your binary files using ZLIB and the compression system that comes with Archive and ArchiveBase
If you need more exact details / code samples let me know
My main computer is down right now (needs new motherboard) so its not that easy for me to get code samples.
Rama
Hmmm, that looks useful, but I can’t figure out how to use it to get the object list. Any code samples would be cool, but I get if you can’t do it, motherboard failure is not fun
you would load each level
then use the ObjectIterator to go through all your objects of your chosen classes
you could also use the actor iterator
#My ActorIterator (specific classes only) Tutorial
http://forums.epicgames.com/threads/972861-TUTORIALS-C-for-UE4-gt-gt-New-Change-Global-Post-Process-During-Game!?p=31667115&viewfull=1#post31667115
then write out each object / pickup to file
then when each level loads
it loads its set of objects
and if they are marked as already being picked up, or only show up on certain difficulty levels, you can decide whether to actually spawn them or not
thus you create the effect of persistent item status while visiting and revisiting levels
and also have a perpetual listing of all items in a level and their picked-up or other status (including locked doors and such)
telling you
you can do ANYTHING with UE4 C++
and writing all your persistent level status out to file gives you easy database of all info about all levels
#Open Locked Doors in Other Levels
so then you can open a locked door in a different level without even streaming in the level
Rama
#Regarding Code
if you still havent gotten something going in a couple of days bump this thread and I can work up a tutorial on this subject,
I’m just rather hampered without my main computer.
Ah, I think I see where the problem is. I’m not too worried about iterating or saving the information, it’s just that first line “you would load each level”.
We’re trying to use the level streaming function of UE4 to get around a drop in performance when there’s too many unique actors in the level by having large chunks of actors as a single mesh that gets switched out when we need to access what’s in it.
However, I’d like to be able search through every actor, including the one’s not currently being streamed. So, I’m trying to stream each level in, run an ActorIterator over it to get the information and write it to a file, then unstream it and stream in the next one, etc.
My issue is with that first step, I’m fairly sure it’s possible to stream a level via code rather than blueprint, but I’m not sure how to do it.
#LevelStreaming.h
Have you checked out level streaming .h and LevelStreamingObject ?
#My Opinion
I think you are making things hard for yourself by not just loading each level and writing out contents to file
Unless you have like 100 levels to process
Rama
#Alternative
#SetActorHiddenInGame
Why dont you just hide a bunch of the actors
rather than moving them out to a different level?
TheActor->SetActorHiddenInGame(true);
Doesnt setting them to not render produce the equivalent performance gain of streaming them out ?
I dont know for sure myself that is why I am asking you to test this
Rama