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"

Help with changing a spawned actor

I am creating a third person open world game. I have my inventory system all up and running and works great. Its called BP_Inventory. Currently I have to spawn it on "begin play" Screenshot below. In that screenshot on the spawn actor node you will see i can control the "Amount of slots" my inventory will have. Currently set to 20 if i press play and open my inventory i will have 20 slots. If i end play change the number to 50 then hit play again then this time i will have 50 slots.

The problem i have is that i want to change this at runtime so my player can start with 20 slots then when they get a level up they will have say 50 slots. Because this actor is spawned on begin play it obviously cant be done through a simple variable change.

I did try to create a function that destroys the actor then spawns it again with the new slot amounts, ive ran this through a "do once" node this function is in screenshot below. This works to a point it deletes the old inventory actor and creates the new one with 50 slots but even with the do once node it doesn't stop respawning them in the world outliner i watch it got from bp_inventory to bp_inventory1, bp_inventory2 and so on befor i know it im up into the hundreds and because it constantly spawns it again i cant actually pick up items as they are instantly deleted on the respwan. it also sucks up my system resources from constantly removing and replacing the actor.

Is there something i am doing wrong? is there another way to do this? tried so many different ways with varied results but cant seem to get it working i've tried to place the actor directly into the world rather than spawn it on begin play but then the inventory doesn't work at all. any help or ideas greatly appreciated if more info is needed please ask away ill reply as soon as i can.

alt text

alt text

Product Version: UE 4.20
more ▼

asked Nov 03 '18 at 04:25 PM in Using UE4

avatar image

16 1 4 8

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

2 answers: sort voted first

It looks to me like the problem is with the location of your DoOnce node. A function is encapsulated so it runs and then removes itself after completion, so your DoOnce is essentially ignored.

I think if you move the DoOnce outside of the function, and place it just before the call to the function, you'll get better results.

more ▼

answered Nov 09 '18 at 12:35 AM

avatar image

111 2 3 4

avatar image mattyi85 Nov 09 '18 at 01:02 PM

brilliant thanks for the sensible response worked like a charm as soon as i took the do once out of the function and into the event graph it stopped firing it hundreds of times. I wasn't aware that they couldn't be used inside functions thanks so much :-)

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

I am not quit sure what you want... you might just run a branch (and a squenz if you have the slot occupied) from event tick. So every frame the player character checks if the player has a level up if he has change the inventory size to 50 solots if not to/or remain on 20? I dont know how many things you have on event tick and if it might causes some perfomance troubles but it would be the first thing that comes to my ming. Other than that you might create a custom event that when the player levels up or when he spawns checks the current level and assigns the proper slots. Is that the answer? I hope I could help :D

more ▼

answered Nov 03 '18 at 04:33 PM

avatar image

10 1 4

avatar image mattyi85 Nov 03 '18 at 06:01 PM

I don't think you get the question. You can't put a spawn actor node on an event tick or it will constantly try to spawn the actor on every tick. Even with a "do once" node it still spawns on every tick as explained and screenshot above. that can also only be done by destroying the actor first which also destroys any current items in the inventory but then it gets stuck in the loop as explained above of constantly destroying and spawning the actor..

If i dont destroy the actor and just use the same actor because it is spawned on "begin play" its variables cant be changed at runtime because it was only executed at "begin play". if i call it anywhere else tick event or custom events it gets stuck in the above loop no matter what branches or nodes i put before it the "do once" node should stop that happening but it doesn't.

avatar image Max2066 Nov 08 '18 at 05:18 PM

"You can't put a spawn actor node", no you should use a variable ...to check and then.... the variable affects the player...

avatar image ThompsonN13 Nov 09 '18 at 12:26 AM

where /when are you calling the respawn function? if you have it based on a leveling system like you mention then you would just call the respawn once when the level up occurs. though theres probably other issues at play here as well and there is also probably a better way of handling the addition of inventory slots.

(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