C
C#15mo ago
Theos

❔ Zenject (Unity) doesn't fire when i do new()

Hey, I have a class which looks like this
public class Something
{
private A _a;

private B _b;

public Something(A a)
{
_a = a;
}

[Inject]
public void Construct(B b)
{
_b = b;
}
public class Something
{
private A _a;

private B _b;

public Something(A a)
{
_a = a;
}

[Inject]
public void Construct(B b)
{
_b = b;
}
public class Test : MonoBehaviour
{

public void Start()
{
var smth = new Something(_a);
}
}
public class Test : MonoBehaviour
{

public void Start()
{
var smth = new Something(_a);
}
}
and _b is null for some reason?
10 Replies
Theos
Theos15mo ago
B is binded, thats for sure
Thinker
Thinker15mo ago
Idk what Zenject is but everything here looks consistent
Thinker
Thinker15mo ago
You're calling the constructor, so only the constructor is being run. There's no magic here.
Theos
Theos15mo ago
nope, zenject should call Construct thats why there is the [Inject] thingy
Thinker
Thinker15mo ago
Does it do IL weaving or something?
Theos
Theos15mo ago
no clue tbh
Thinker
Thinker15mo ago
ah, yeah, looks like it is
Theos
Theos15mo ago
i guess i cant use [Inject] if i'm constructing classes on my own it should either be a MonoBehaviour or a class created using Zenject
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server