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"

[4.7] Keep pointer variables in-between levels.

Hi everyone,

So I'm wanting to keep my inventory class in-between levels set to the same variable. I have a GameInstance class setup and it has been working great for my primitive variables. However, I'm trying to work with keeping my inventory object in memory by setting it in my GameInstance. I'm wanting to pass my inventory as I am loading into a battle scenario and I transition into a battle level, My inventory is a child of UObject also. My issue is that once the level transitions, my variable is now invalid. I want to say it is because it is a pointer and looses its address but I can't say 100% on that.

Any help on how I can keep my variable set? Also I did try to assign it to a reference variable but it complains about GENERATED_BODY() being private, even when I declare a public at the top of the header. I haven't really worked with reference custom classes in UE4 so any help would be appreciated.

Thanks everyone.

Product Version: UE 4.7
Tags:
more ▼

asked Jul 14 '15 at 01:57 AM in C++ Programming

avatar image

5Kwatts
117 12 9 16

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

2 answers: sort voted first

Actually, I just had an epiphany and the idea hit me. I didn't put UPROPERTY() on my inventory manager variable and that was the reason why it was being GC. This solved my issue during transition.

more ▼

answered Jul 14 '15 at 05:07 AM

avatar image

5Kwatts
117 12 9 16

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

Hi 5kwatts,

UObject object pass through levels with host in GameInstance class or GameSingleton class all works well in my situation. But i recommand host in GameInstance class, Singleton has much more problem with object references.

Your Inventory classes should be pure data struct or data container and do not reference any Actor references, because actors are hosted in world and will be destroyed on level end, but uobject in gameinstance will not destory. You can rebuild your inventory widget from UObject data in new level begin play event.

This pattern called MVC, model, view, and controller. pure data objects are models, umg widgets are views. gameinstance, gamemode, playercontroller,levelbp are controllers.

Hope this can help you.

Cheers
Omega

more ▼

answered Jul 14 '15 at 03:49 AM

avatar image

Omega
265 15 19 24

avatar image 5Kwatts Jul 14 '15 at 05:09 AM

Hi Omega,

Thanks for your response but I wasn't actually trying to manipulate it via UMG. I was setting a variable and making sure it was being set and kept its data during level transition. Turns out it was being garbage collected. I added UPROPERTY to it and it fixed my issue. I forgot that the engine does that on variables.

(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