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"

Updating actors on different levels

In many older games, if you enter a building, a new level with its interior will be loaded. I will base my question on the game: "Harvest Moon", where such a mechanic was implemented. A new day always starts and ends inside the main house.

Now, how can you for example update the plants growing outside the building? Doing all the calculations inside a GameInstance seems a little bit weird... Is there any better way to achieve this? I thought about level streaming, but the interior and exterior dimensions of the house do not match...

Screenshots of the levels:



Product Version: UE 4.21
more ▼

asked Feb 15 '19 at 01:56 PM in Using UE4

avatar image

19 3 3 4

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

1 answer: sort voted first

if using two separate levels where one is loaded and the other is unloaded, the issue is that the unloaded level ceases to exist when unloaded. this leads me to two possible solutions. first though some assumptions, im assuming that the situation is something like you plant some plants and after each day they are meant to grow a bit.

ok so for the first possible solution you could create a array which contains the pertinent information about each plant (location, growth stage int, class, etc). then you dont really need to worry about the level being unloaded you could instead just spawn the plants back into the level on begin play.

the second solution would be to use level streaming. in this case however you would not have the house level actually in the house mesh you would place it elsewhere such as below the terrain and just teleport the character there. this would allow you to not unload the level which eliminates the issue.

more ▼

answered Feb 15 '19 at 02:31 PM

avatar image

10.1k 33 10 25

avatar image BlackBird604 Feb 15 '19 at 04:20 PM

Well, there is a problem with the first solution... It's unfortunately a bit more complex and requires more than adding a number to the growth stage...

At the beginning, the field is only sown and there is no plant actor.

In this state, there is a small chance of weed appearing on the field, which will prevent the plant from spawning.

Furthermore, the time between growth stages can be reduced by watering the field (by player or rain).

Is it possible to store inside a GameInstance some sort of manager that would handle updates of field and plant data?

avatar image BlackBird604 Feb 24 '19 at 09:03 PM

Thank you very much ThompsonN13. I followed your advice and I implemented it based on structures and UObjects. Technically, it works, but I don't know whether my solution is correct/reasonable or not...

The general hierarchy of actors looks like this: a GridActor has an array of FieldActors which have a PlantActor. The data structures are created in the same way: GridInfo has an array of FieldInfos and each FieldInfo stores a PlantInfo (each struct has some more variables).

After each day the GameInstance creates a temporary GridUpdater (UObject) which is responsible for updating the field data. It takes the whole GridInfo structure as parameter. The GridUpdater creates then a temporary FieldUpdater (UObject) and passes each FieldInfo (one by one) to its update function. Finally the plant data is updated after creating a temporary PlantUpdater (UObject) inside the FieldUpdater and executing its update function with the PlantInfo structure as parameter.

My problem is now as follows: I have no idea when (and where) should I write the code to save the structures into my GameInstance. Would the EndPlay function of the FieldGrid be an appropriate place to do this?

avatar image Crowley Caine Feb 24 '19 at 11:40 PM

He has a very good response to this, I would've handled it by using a function that takes in the time passed and simulated the various events taking place, then updating the level with the output from the simulation.

(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