Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

485
Views
Subscribe static methods to EventHandler Unity

I have an EventHandler that is static which can be subscribed to from anywhere.

public static event EventHandler<CustomEvent> OnChunkLoad = delegate(object sender, CustomEvent ev) {  };

I can subscribe non-static methods like so and this work perfectly when the handler is raised.

EventHandlers.OnChunkLoad += whenChunkIsLoaded;

public void whenChunkIsLoaded(Object obj, CustomEvent ev)
{
    print("Loaded\n");
}

But now I want to be able to subscribe static methods at runtime automatically and allow them to be called when the handler is invoked.

Right now the only way to do this is to have some static method called at startup to subscribe all static methods I want to subscribe.

public static class StaticMethods
{

    // call this on startup
    public static void registerMethods()
    {
            EventHandlers.OnChunkLoad += whenChunkIsLoaded;
    }

    public static void whenChunkIsLoaded(Object obj, CustomEvent ev)
    {
            print(ev.DateTime + " : " + obj.GetType());
    }
}

Even though this would work it is messy and eventually become very long after awhile. Any help, Thanks.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!