Hi guys.
I have the below variables
When I do the below action, all of them turn to FALSE as I want them to
However, later when I turn them to TRUE I feel like the variables do not change, as the game isn’t running as I want it to. (The enemies are supposed to start spawning when their value is TRUE)
In order for them to work properly, I need to turn them into True one by one.
Is there a reason for this? Why can I turn all of them into FALSE without specifying which one but not the opposite?
When you use a structure variable name without any children, it changes the variable from a structure into the type that you use. The children get removed. If you try to read a variable or child name that doesn’t exist it gets created as that type. In your case, a Boolean with the default value of false.
It’s best not to use the variable name by itself. It’s better to always include the children names and set them individually.
It might be easier to put the objects into a group and use an object Boolean. You could set then set them individually or all at the same time using the group name.
Set Enemies.spawn to false
If enemies.spawn is true
(Depending on what you do, you might need to use for each object)
You could do change the structure variae dynamically or you could use for each child Although, I don’t think you have enough children variables to make using for each child worthwhile. Plus, if you always set them to the same value then you wouldn’t need to use individual children names. Other than to reset them all at once.
I don’t know in what context you’re reading the values. It might be easiest to read and set them as a group object.
1 Like
Thank for the reply @Keith_1357
I suppose this makes sense. I didn’t know that structures work like that.
Just to get an idea, the above variables where working as an indicator of when to enable the spawning of the mentioned enemies. The 4 enemies variants spawn randomly and the scene can have a lot of them at the same time. Sometimes there are special events in my game where I don’t want to spawn enemies cause I already have pre-made formations of them in the layouts that is created.
Because of that I don’t think it fits to make an object boolean, I also want to limit the “for each object” events when not necessary in order to save performance as I have a lot of them.
I think for the time being I will either make one boolean variable that will control all of them or just enable/disable the mentioned variables manually on each event.
1 Like
That sounds good. It does make a lot of sense to limit the use of for each events. It can affect frame rate. It makes sense to have one child variable per object or enemy type.
It seems counterintuitive at times that you sometimes need to create more events to be more efficient but it’s a matter of using the right events. It’s not the number of events but the number of events that get processed per frame. Looping multiplies the process time.
1 Like