How to spawn and actor with diferent variables values each time it gets spawned?

Hi.

Everytime i press “u” it spawns an actor with a set of variables, then call an event inside that actor and set random numbers to those variables:

The event creates a randomized weapon based on the number recived:

The gun gets created proprely but it seems sometimes i cant acess the propeties of the weapon parts, if i do this way above.

When i had this gun creation code on construction script i could acess the properties with no problems, but when this proertis are set on the custom event i cant acess it well

This is how i am trying to acess the weapon properties on my player character:



Then this node influences how the character will shoot:

With the Custom node that creates the random gun tsome of those propertis doesnt get acessed, but the exate same code on the construction script works like it should.

so my question is: Is there any way to set the variables of a certain actor after it gets spawned?

Do you mean during coding? Likely. Because the event graph is a runtime thing.

I’d take a serious look at using arrays and possibly also structures. You could simplify all this code to one chain of nodes with that.

This

would become

2 Likes

Thank you for the sugestion, but do you know how can I set a spawned actor variables on spawn, for example: i wanted to each time a spawn a weapon this would have diferent fire rates, recoil etc… Like i said before, i was able to do this in construct script but only worked with random ints or predifined int values, but now i want to be able to build my weapon…

If you make the variable ‘instance editable’ ( the eye ), then on the actual spawn node, you can set them :slight_smile:

1 Like

I found that the problem was that when spawn the value would get multiplied and get huge numbers, resulting on the values like fire rate to by increased (resulting on slower fire rate, since the fire rate is the time between the shots), dont know why tho, i tried to put a do once node on the create weapon event but still multiplies the numbers but not so much like before…

Ok, that’s a coding problem. Get it to work with other variables, and come back to that.

1 Like

It was a the event tick that was causing it, it solved now… Thanks for the help :slight_smile: One more thing if its not much to ask:

When i drop the weapon, instead of keeping the parts, the guns resets to its defaults, Im doing the same principle of creating weapon as before but now at a diferent location, I keep the variables of the gun i own and then transfer to the other spawn actor of class weapon, creating a new gun with the same stats and parts and deleting the one i owened, but this time its doesnt keep the varibles i was supose to transfer, resulting on the weapon getting reset to the default values.

Ps: im doing this instead of deatch actor because i dont want it to be a child actor (because of save games issues)

Hmmm, it must be that the settings aren’t getting through, somehow. It will be in your code, just work through it slowly… ( lots of print strings ( easier that the debugger ) )… :slight_smile:

2 Likes

Yep print string does miracles :wink: it was the first variable “weaponType” that wasnt passing thorugh ty very much for the help :slight_smile:

1 Like

Sorry for keep asking questions, but my spawned weapons are not saving its varaibles even if they are set to save game:

Everytime i load the game the weapons are on the saved spot but back to their default state…

Here’s my save game 101:

It needs to happen in this order.

1 Like

This is how my save game is currently working:

I get all actor of the level and store those in an array, shouldnt this be suficient to store the all the variables inside those actors?

Nope :slight_smile:

Don’t save actor references. I don’t think it works after packaging.

But anyway, even if you could, anything associated with the actor doesn’t get saved ( only the outliner name ).

You need to pack all the class types and settings into an array of structs. When you later read the save game, you can create the classes and reset the settings from the structs.

That’s the way it is with the save gave. It does nothing for you… :grimacing:

1 Like

Yeah i had to resource to arrays of structs and its working just fine thank you very much again :slight_smile:

1 Like