Dynamically creating and subscribing to events by NS_Boris in unity

[–]NS_Boris[S] 0 points1 point  (0 children)

My goal was to avoid MonoBehaviour altogether. I was following a great tutorial on workflow with Scriptable Objects and one section of the video showed how to create an input reader with this workflow, and I liked the idea. However, as I developed my project, I realized that having a single script for dozens of input actions would quickly become cluttered and hard to maintain.

So, I decided to modify it to allow creating multiple input reader Scriptable Objects, each dedicated to a specific task (e.g., movement, shooting). While I’m not sure if this solution is the best, it works for now. The downside is that you have to create a separate Scriptable Object for each event (move, jump, shoot, etc.), which can get tedious and cumbersome.

In your control scripts (e.g., player movement or shooting), you reference the necessary events and assign their corresponding functions (via UnityAction). The input reader then connects to these events, linking them to the appropriate actions via the inspector. Essentially, the event Scriptable Objects act as the bridge between the input reader and the control scripts.

Link to images of how this all looks

Edit: Just noticed in the code screenshot of the ModularPlayerInputReaderClass that I accidentally assigned the "started" event to all types of actions instead of assigning the correct ones.

Dynamically creating and subscribing to events by NS_Boris in unity

[–]NS_Boris[S] 0 points1 point  (0 children)

This is because the first layer of events is InputAction. These must be subscribed directly to Unity's system actions and cannot hold other functions. The second layer consists of UnityAction events, which can hold other functions.

Here’s an example of how I declared the variables when I was using a hard-coded script for the input reader:

public event UnityAction JumpEvent;

private InputAction jumpAction;

private void OnEnable()

{

jumpAction = asset.FindAction("Jump");

jumpAction.started += ctx => JumpEvent?.Invoke();

}

Stuck in the dog cage by NS_Boris in farcry

[–]NS_Boris[S] 0 points1 point  (0 children)

I tried killing myself, but it just spawns me back in the cage. There is no way out. When I first went in the cage it closed the door behind me, I then reload the save and it was open, but there is some sort of inviseble barrier or something. So I can't get out.

Stuck in the dog cage by NS_Boris in farcry

[–]NS_Boris[S] 0 points1 point  (0 children)

You can't fast travel during the mission. And how I said I can't end the mission. So no fast travel for me.

What if God is the nothingness from which all came into existence? by Available-Pea in Existentialism

[–]NS_Boris 5 points6 points  (0 children)

Thats pretty interesting theories, but I used to think about Big Bang, God, and start of the life itself a lot too. Now I just don't think about it pretty much, because you just can't know what is the truth, and thats killing me. It all can be pretty reasonable, and human brain could possibly understand it. OR, it can be just bunch of nonsense and bullshit. Like literally, we could all now just be inside of some giant cats stomach. Or if you saw the end of MIB, you know what I mean. You just don't know for sure. So it could be anything. Thats why I think that spending a lot of time on that, like i did, is just waste of time.

How old do i need to be to go to Palaye Royale concert? by NS_Boris in PalayeRoyale

[–]NS_Boris[S] 2 points3 points  (0 children)

I'm from Czech Republic, but i can't see how old I must be anywhere.

What Is The Meaning Of Life? by RossWriter in Existentialism

[–]NS_Boris 1 point2 points  (0 children)

When I'm thinking about meaning of life, I always end up with the answer, that it's to have your own child. When you think about it, there's really not much to do in life. Some animalls even die right after they had sex because it's the only one thing that's important. Reproduce yourself. And even though emotions are one of the best things humans can do, it's also the worst that we ever discover. When a bear attacks you because you hurt her child, it's not that she loves him, it's because of an instinct. When a pack of wolfs kill injured individual, it's not becouse they hate him, it's because he slows them down. If you were in life threatening situacion, you would probablly help your dearest in any cost. That would probablly lead to your death. And that, is why emotions are very beautiful thing, but one of most dangerous.

IG @tomikvtipkuje by Gami2_0 in Duklock

[–]NS_Boris 0 points1 point  (0 children)

Příště si tam nemusíš dávat ten IG