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"

[Question] Level Streaming in C++

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?

Product Version: Not Selected
Tags:
more ▼

asked Mar 11 '14 at 02:38 AM in C++ Programming

avatar image

ue4-archive ♦♦ STAFF
49.9k 3660 1983 9111

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Mar 11 '14 at 02:38 AM

avatar image

ue4-archive ♦♦ STAFF
49.9k 3660 1983 9111

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:38 AM

That's exactly what I was looking for, thanks Marc!

(comments are locked)
10|2000 characters needed characters left

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

more ▼

answered Mar 11 '14 at 02:38 AM

avatar image

ue4-archive ♦♦ STAFF
49.9k 3660 1983 9111

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:38 AM

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 :p

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:38 AM

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

ttp://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

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:38 AM

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.

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:38 AM

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.

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:38 AM

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

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:38 AM

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

(comments are locked)
10|2000 characters needed characters left
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