#Looking for Advice!

1 messages · Page 1 of 1 (latest)

dense vessel
#

Hey! I'm just learning how to use SO's as an event container, but I'm wondering if I could get some feedback on optimizating or any major errors I'm making with the system. I'm currently running into the problem of each of the event reoccuring when the player does an action that calls them. I tried to flag it so that It could only be called once, but It's pretty ineffective and I realize that I'm doing it wrong. Additionally I don't really think I'm utilizing the Enum to handle the progression?

https://codeshare.io/deYZdZ

#

Here's a video on the system at work at the moment (Apologies for the mic buzz)
(honestly I would mute it and just skip through)

worldly patio
#

So the problem is that when you do one thing, all the events occurs?

jade talon
#

where is the logic that tracks which progress state you are in and calls the appropriate Raise___ function?

dense vessel
#

Event's properly are called, the problem is I'm having trouble preventing them from being recalled, the way the it's currently set up, in the code share I gave all three scripts as example. The scriptable object will call an method that serves as the invoke for the event, each event on the ui has a method
I.E

public void RaiseOnSeedCollected(ProgressState state)
    {
        onSeedCollectedEvent.Invoke(state);
    }```
#

and an associated enumerator for that event

[System.Serializable]
public class GameProgressEvent : UnityEvent<ProgressState> {}

public enum ProgressState
{
    None = 0,
    SeedCollected,
    SeedPlaced,
    Incubating,
    IncubationComplete
}
jade talon
#

what do you mean "re-called"?

#

when does it happen again?

dense vessel
#

So for instance, I have an event that when the player picks up a seed, it will call an event that updates the UI to display text prompting them on how to move forward within the game

#

Once they've met another condition it will invoke the next event and move forward

#

At the "end of day" it will move to another scene and come back to the original scene

#

However at any point if the player were to pick up a seed again, it will reinvoke the same event

#

for the original seed prompt

#

however in the seed UI handler class, it should be preventing this reinvoke because the invoke is only supposed to happen if the boolean state is false

 private void HandleSeedIncubating(ProgressState state)
    {
        if (!seedIncubatingMessageShown)
        {
            UpdateMessage("It's still got some time in the oven, in the meantime; you can either farm or keep waiting. Don't forget to get some rest in the pod.");
            seedIncubatingMessageShown = true;
        }
    }```
jade talon
#

well... i'm not sure what's causing the problem. but i'd say maybe serialize those bools so you can view them in the inspector and use debug.log's to give an output when you invoke those methods.

#

because if it's setting the bools to true and then displaying the message anyway, and it's the same class, that's pretty wacky

dense vessel
#

It might be something to do with the reload of the scene

jade talon
#

so it only re-shows the message after a scene change?

#

if so, then yes that might be the problem. pretty sure a change scene destroys all objects and then a scene load recreates them, with all initialization

#

so if that's what's happening, it's resetting your bools to false

dense vessel
#

ahhhh, should I make sure it's don't destroy on load?

jade talon
#

that or perhaps a simpler solution would be to change your scene change

dense vessel
#

In that case I just have to make sure it's a singleton so it's not making another instance

jade talon
#

i mean... your "message" could just be an overlay ui that doesn't actually end the scene

#

in other words it might be cleaner to have your "end of day" stuff just be within the same scene

#

i don't know what you do there but if it's just UI for example, one easy way to do it would be to make a screen-sized panel that goes over everything and shows your UI on that panel, then disables it when done

dense vessel
#

I would totally do that but my teammember is handling that system and my project manager doesn't want it done any different

#

Dotween stuff

jade talon
#

ahh i see

dense vessel
#

Haven't touched it

jade talon
#

then yes you will need to maintain all of your state when you return to your scene

dense vessel
#

I'm working with three other programmers so I can only tweak so much

#

For sure thank you man!

jade talon
#

what you might want to do in that case is implement your save mechanism

#

then you can just "load game" and you get that functionality for free

#

or something, there's a lot to consider here and i'm not sure of the best answer

dense vessel
#

I think we're using Json to save the game but that's a him problem lol

jade talon
#

fair enough... i mean... if you can get that to work together, you'd do the save/load at end of day and you'd get auto-save for free

#

dunno, just trying to save you some work

dense vessel
#

Yeah I really appreciate it, I'll try to make sure it doesn't destroyonload and get back to you if it's not the solution

#

Thank you so much for your help!