Mysteries Errors


  • Cool, so there is a way to add date to blog post, but I need to add the component myself? Maybe there is a template or some sort…not like a block pattern that I still need , but actually automatic.
    • Ah, yes. As I type that, editing the post template just make sense and there is no reason to add date in title anymore.
  • Seems like C# in Unity also got the issue of “this is null”…I understand they are functions that can be static, but the language should know that. It will be nice when a function is being called on a variable that has yet to be initialized it will fail right there instead of inside whatever function it is calling. Pretty sure there are times it does handle it properly…
  • When making DLLs for your Unity project, including C++ solution into the C# solution won’t be needed. Seems like it used to be the right way but it no longer works. Just have the C++ solution generate the DLLs into the right location where C# solution can get.
  • Circular dependency in blueprint is still the devil for Unreal engine. Since it couldn’t detect it, it will just break some random, unrelated things. The best way to fix it is just walk through the changes and find out which one happened to be the one who completed the cycle.

Unity Input Systems

When making input systems, sometimes you ended up with a number of inputs are basically the same, but have to be implemented separately. For example: ctrl + num

I was using the Unity Input Action System, and ended up having a huge number of input actions: ctrl + num, shift + num, alt + num, and even just the number key needs its own input. That is 40 of them with 4 different actions.

It is going to be really annoying to go through all 40 of them and assign proper callbacks, not even saying the difference will just be the integer that got passed in…

The right way to handle it with grace is get the property(variable) with name. Lucky Unity Input Action System allows us to do that with C#.

Make your input action assets into code and you can access the input actions as below:

[C#]
m_myInput = new MyInput();

for (int i = 0; i < 10; i++)
{
    string index = i.ToString();

    string inputActionName = $"InputAction{index}";

    //MyInputActions means it is under Action Maps "MyInput"
    var inputActionProp = typeof(MyInput.MyInputActions).GetProperty(inputActionName);

    m_MyActions[i] = (InputAction)inputActionProp .GetValue(m_myInput.MyInput);

    //need to capture new variables for each lambda
    int capturedIndex = i;
    m_MyActions[i].performed    += ctx => MyCallBack(capturedIndex);
    
}

Not satisfied with that code block up there, but it will do for now.

Published by


Leave a comment