V
V
Vlad-12345678902022-04-13 16:27:11
C++ / C#
Vlad-1234567890, 2022-04-13 16:27:11

Is it possible to pass a reference to a variable into an array?

In general, there was a small problem. There is an array which should store references to 2 structures in itself.

[SerializeField] private Stat _health;
[SerializeField] private Stat _damage;
private Stat[] _upgradableStats = new Stat[2] {_health, _damage};

is it possible to pass _health and _damage by reference without making Stat a class?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Morrowind, 2022-04-13
@Vlad-1234567890

Hey!
In general, your idea of ​​\u200b\u200bthis crutch is not entirely clear.
Perhaps you want to sort through the array somewhere further and pull these fields. Question : why?
Moreover, your fields are private.
I suggest you simply reconsider the way you use an object with specified fields.
You will use a class and pull its public fields.
There is no other way to interact with an object to change it (at least I have not heard of such magic yet. Please correct me if there is one).
I remind you that the properties and methods of an object without an "instance" (initialization of a class \ object in memory) will not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question