#Bins scriptableobject adventure
1 messages Β· Page 1 of 1 (latest)
Amazing title
lol i know
Ik I'm not the best at unity but got a harsh deadline and at my "company" our staff got limited to four people including me so RIP
rip
i guess
Alright
Which lol
where the instantiate elements
alright
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class InstantiateElements: MonoBehaviour
{
public GameObject flaskOriginal;
public GameObject flaskContainer;
public void cloneElement()
{
GameObject elementClone = Instantiate(flaskOriginal, new Vector3(1, flaskOriginal.transform.position.y, 0), flaskOriginal.transform.rotation);
elementClone.transform.parent = flaskContainer.transform;
elementClone.transform.localScale += new Vector3(2.448037f, 2.448037f, 2.448037f);
elementClone.SetActive(true);
}
}```
right so you need a reference to an element right
to be able to like
put the element on the thing y'know
attach the SO to the element handler ye?
ye i guess
So, from what I understand I put elementHandler.cs on the button that makes an instance of the element, yes?
i dont know what the elementHandler is mate
And then attach the SO to the element handler
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class compoundHandler : MonoBehaviour
{
public elements element;
void Start()
{
}
}
this basically
Okay
attached it to the UI button
and then attached the SO to it
now this yes?
elements element = GetComponent<compoundHandler>().element;```
yeah
and I attach it to the script that makes an instance of a flask yes?
yes
np
I grew in dev communities where pretty much everyone is toxic
you know that feeling
yeah
btw im still not very sure about this since i dont really know your code structure soo
well
we're about to find out
rip
NullReferenceException: Object reference not set to an instance of an object
bet it's this
NullReferenceException: Object reference not set to an instance of an object
InstantiateElements.cloneElement () (at Assets/database/InstantiateElements.cs:12)
yup
yeah so
you either don't have a compoundHandler on the same object
or the compoundHandler doesn't have an element attached to it
yup
I dont
just thought of it
wait so I don't attack the compoundHandler on the button but on the gameobject that is being cloned
*attach lol
you want a screenshot or something
ah
it's prob because there isn't anything attached to the element
righttttt
you could put all the scripts related to this in a bin website i guess?
would help me a bit
but how do I attach it then rip
pastebin is fine?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
pastebin does too
oh it does now
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
the titles are the file names btw
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
here
that's all?
yup
is the compoundHandler on the flask?
yes
alright
then you can just get the element by doing ```cs
elements element = elementClone.GetComponent<compoundHandler>().element;
almost forgot the .element
instead of cs elements element2 = GetComponent<compoundHandler>().element; ?
ye
ok
gotta be after this line doe
got it
nice
bruh
NullReferenceException: Object reference not set to an instance of an object
still
then you probably don't have an element on the compoundHandler
on your prefab or whatever flaskOriginal is
thing is that there will be more elements right
I cant just set one of it onto the flask
there will be many of them
hmm you're right
i would probably have the cloneElement function take in an element and then just set the flask's element to that
so uh
and then when you press the button somehow figure out what element to pass in
basically assign all of them to one flask?
?
no your flask prefab got no element
when you instantiate it you give it the element
ye
since you can't really have all elements in one flask
but wdym take in
i guess
but you gotta figure out what element to pass in when you press the button
somehow
maybe based on the text on the button?
mayb
but uhhh
sorry but um
i dont see how that parameter would work
I would attach all of them to it?
yes
and after you instantiate it
you do ```cs
elementClone.GetComponent<compoundHandler>().element = element;
well yeah but how do you set what element it is in the parameter
ik im annoying but ye
after that I'll be quiet
that's for you to figure out ig
i dont really know
lol
ok maybe just do a bunch of ifs idk
ig
so like
public void cloneElement(elements element)
{
if (element.name == "Na") {
elements element2 = elementClone.GetComponent<compoundHandler>().element;
}
}```
idk
lmao
Hold on let's get back to square one
aight
we use SO for info for elements right
yes
hmmmmm
Wait
would something like
element[_text] work
instead of the dot
for example
element["valance" + _text]
basically
to make everyone's lives easier
instead of making a SO for each element
we could like
an array?
make a db for the elements in a single SO
tried json before
yes
ughhh
hold on
so
after a button is pressed in a UI
It will instantiate a flask
yes
The idea is that this flask will have the SO with info regarding that element
so if I click "sodium"
A flask will instantiate
and SO called "Sodium" will be attacked to the clone
by using a compoundHandler
i dont see the problem if you have multiple buttons
yes
yes
so
from what I understand
public void cloneElement(elements element)
cloneElement(elementClone.GetComponent<compoundHandler>().element);
and you have the instantiate whatever
it should have a parameter right next to the thing
OH
and that's where you attach the SO
lol
so, put something in it?
" must declare a body because it is not marked abstract, extern, or partial"
wait
wait
oh fuck
I just realised
you were referring to this?
public void cloneElement()
{
GameObject elementClone = Instantiate(flaskOriginal, new Vector3(1, flaskOriginal.transform.position.y, 0), flaskOriginal.transform.rotation);
elements element2 = elementClone.GetComponent<compoundHandler>().element;
Debug.Log(element2.name);
elementClone.transform.parent = flaskContainer.transform;
elementClone.transform.localScale += new Vector3(2.448037f, 2.448037f, 2.448037f);
elementClone.SetActive(true);
}```
yes
π
π
i love this community
me too
what
is it not cloned tho
just call it method
ok
so
maybe um
public void cloneElement(elements element, GameObject flaskOriginal)
{
GameObject elementClone = Instantiate(flaskOriginal, new Vector3(1, flaskOriginal.transform.position.y, 0), flaskOriginal.transform.rotation);
elements element2 = elementClone.GetComponent<compoundHandler>().element;
Debug.Log(element2.name);
elementClone.transform.parent = flaskContainer.transform;
elementClone.transform.localScale += new Vector3(2.448037f, 2.448037f, 2.448037f);
elementClone.SetActive(true);
}
}```
didnt u already have it declared tho
i did but the code itself is on the flask
so
it isnt on the button
wait
sudden realisation hits the fan
I'm starting to wonder what drugs I did
yup
NullReferenceException: Object reference not set to an instance of an object
InstantiateElements.cloneElement (elements element) (at Assets/database/InstantiateElements.cs:15)
wait
line 15 is
Debug.Log(element2.name);```
bro
π
I should remove it probably
elements element2 = elementClone.GetComponent<compoundHandler>().element;
Debug.Log(element2.name);```
yes
so you dont need to worry about that
so I can remove it
because what we wanna do is ```cs
elementClone.GetComponent<compoundHandler>().element = element;
element = element seems like a bad idea
they're different
elementClone.GetComponent<compoundHandler>().element and element are two different variables
ik
so
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class InstantiateElements: MonoBehaviour
{
public GameObject flaskOriginal;
public GameObject flaskContainer;
public void cloneElement(elements element)
{
GameObject elementClone = Instantiate(flaskOriginal, new Vector3(1, flaskOriginal.transform.position.y, 0), flaskOriginal.transform.rotation);
elementClone.GetComponent<compoundHandler>().element = element;
elementClone.transform.parent = flaskContainer.transform;
elementClone.transform.localScale += new Vector3(2.448037f, 2.448037f, 2.448037f);
elementClone.SetActive(true);
}
}```
this should suffice?
looks like it yeah
IT WORKS
YEAHHH!!!!1
Thank you so much man
np
How much do I pay
none
u sure?
yeh
np
lol
gn
*good night!
wait actually one more thing
@chilly quarry
one more thing and I will leave you alone dw lol
so
we assigned the SO to another flask
but now
how to do like
"reactions"
aka how to get data from that flask
when it comes in contact with another
just get the compoundHandler's element and do some magic
i think you're thinking a little bit too big if you're trying to code chemistry
rather a proof of concept
right
as I said
four employees
no proof of concept
need to prove this is possible
anyways
var myComponent = hitCollider.gameObject.GetComponent<compoundHandler>();
?
ye
myComponent.element i believe
alright
yes
thank you so much
off to the cryonic station I go
to not be heared of in another 10 years
@chilly quarry ok seriously one last thing
it shouldn't be difficult but uh
dk how to solve it
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
basically what I want to do here is to uh
actually dont mind the first part
else
{
if (!gameObject.name.Contains("lab")) // if the gameobject has a compound
{
compoundData.element = compoundData2.element;
hitCollider.gameObject.name.Replace("lab", "");
} else if (!hitCollider.gameObject.name.Contains("lab")) // if the flask that hit the gameobject has a compound
{
compoundData2.element = compoundData.element;
gameObject.name.Replace("lab", "");
}
}```
this is the problem
basically the firs part will only work if other flasks have the SO in them
So you first need to put the substance in the flask
that's what it's supposed to do
but it doesn't do that
idk what's wrong tbh
error is ```cs
NullReferenceException: Object reference not set to an instance of an object
InteractionRadius.React (UnityEngine.Vector3 center, System.Single radius) (at Assets/Scripts/InteractionRadius.cs:41)
InteractionRadius.Update () (at Assets/Scripts/InteractionRadius.cs:72)
but thing is that it can't react because the flask does not have the thing
oh wait
yeah still doesn't workkk
somewhere in the script you forgot to refer what the component is
what is it saying at line 41 and 72?
got lessons, will answer later aight?
aight take your time
SO UM
@graceful temple
*so um
*caps
wait
it works now
aight
made a typo
π
π
now its time to optimalize this...
um
abomination
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I mean just look at it
yanderedev would be proud
I want nothing to do with that scam
lmao
anyways
i just mean all the if statements
Ik
that's what i'm talking about as well
but there isn't actually a lot I can do
And mind you this is for now the part for hydroxides
for sure
let me have a look
as long as it'll still work I'm up for it
yea ik but i have no clue rn how
so what does it do
what is ```cs
compoundData.element.name
so
and compoundData2
this reads the name of the eleement
from SO
var compoundData = hitCollider.gameObject.GetComponent<compoundHandler>();
var compoundData2 = gameObject.GetComponent<compoundHandler>();```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class compoundHandler : MonoBehaviour
{
public elements element;
void Start()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Element", menuName = "Element")]
public class elements : ScriptableObject
{
public new string name;
public int valance;
public bool reactsWithWater;
}
actually idk at the moment
i dont quite understand the code since i structure mine different
you will have to do it yourselve
alright