#Bins scriptableobject adventure

1 messages Β· Page 1 of 1 (latest)

chilly quarry
analog quail
#

Amazing title

chilly quarry
#

lol i know

analog quail
#

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

chilly quarry
#

rip

analog quail
#

anyways

#

I attach this to instantiateElements yes?

#

the code I mean

chilly quarry
#

i guess

analog quail
#

Alright

chilly quarry
#

can you show the code tho

#

it would make it easier

analog quail
#

Which lol

chilly quarry
#

where the instantiate elements

analog quail
#

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);
    }
}```
chilly quarry
#

right so you need a reference to an element right

#

to be able to like

#

put the element on the thing y'know

analog quail
#

attach the SO to the element handler ye?

chilly quarry
#

ye i guess

analog quail
#

So, from what I understand I put elementHandler.cs on the button that makes an instance of the element, yes?

chilly quarry
#

i dont know what the elementHandler is mate

analog quail
#

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

chilly quarry
#

ah

#

yeah

analog quail
#

Okay

#

attached it to the UI button

#

and then attached the SO to it

#

now this yes?

#
elements element = GetComponent<compoundHandler>().element;```
chilly quarry
#

yeah

analog quail
#

and I attach it to the script that makes an instance of a flask yes?

chilly quarry
#

yes

analog quail
#

Alright time to try it out

#

btw thank you so much

#

like

chilly quarry
#

np

analog quail
#

I grew in dev communities where pretty much everyone is toxic

#

you know that feeling

chilly quarry
#

yeah

analog quail
#

I am mainly a javascript developer, not a C# one. I make bots not games

#

rip

chilly quarry
#

btw im still not very sure about this since i dont really know your code structure soo

analog quail
#

well

#

we're about to find out

#

rip

#

NullReferenceException: Object reference not set to an instance of an object

chilly quarry
#

double click the error

#

it'll take you where it is

analog quail
#

NullReferenceException: Object reference not set to an instance of an object
InstantiateElements.cloneElement () (at Assets/database/InstantiateElements.cs:12)

#

yup

chilly quarry
#

yeah so

#

you either don't have a compoundHandler on the same object

#

or the compoundHandler doesn't have an element attached to it

analog quail
#

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

chilly quarry
#

yeah i guess

#

i would be rethinking my structure at this point ngl

analog quail
#

you want a screenshot or something

#

ah

#

it's prob because there isn't anything attached to the element

#

righttttt

chilly quarry
#

you could put all the scripts related to this in a bin website i guess?

#

would help me a bit

analog quail
#

but how do I attach it then rip

chilly quarry
#

yeah

#

though i'd appreciate smtn like hatebin

#

since it's got syntax highlighting

analog quail
#

pastebin does too

chilly quarry
#

oh it does now

analog quail
#

the titles are the file names btw

#

here

chilly quarry
#

that's all?

analog quail
#

yup

chilly quarry
#

is the compoundHandler on the flask?

analog quail
#

yes

chilly quarry
#

alright

#

then you can just get the element by doing ```cs
elements element = elementClone.GetComponent<compoundHandler>().element;

#

almost forgot the .element

analog quail
#

instead of cs elements element2 = GetComponent<compoundHandler>().element; ?

chilly quarry
#

ye

analog quail
#

ok

chilly quarry
#

gotta be after this line doe

analog quail
#

got it

chilly quarry
#

nice

analog quail
#

bruh

#

NullReferenceException: Object reference not set to an instance of an object

#

still

chilly quarry
#

then you probably don't have an element on the compoundHandler

#

on your prefab or whatever flaskOriginal is

analog quail
#

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

chilly quarry
#

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

analog quail
#

so uh

chilly quarry
#

and then when you press the button somehow figure out what element to pass in

analog quail
#

basically assign all of them to one flask?

chilly quarry
#

?

#

no your flask prefab got no element

#

when you instantiate it you give it the element

analog quail
#

ye

chilly quarry
#

since you can't really have all elements in one flask

chilly quarry
#
public void cloneElement(elements element)
#

a parameter

analog quail
#

oh

#

and that's it?

#

Ik i'm dumb

chilly quarry
#

i guess

#

but you gotta figure out what element to pass in when you press the button

#

somehow

analog quail
#

maybe based on the text on the button?

chilly quarry
#

mayb

analog quail
#

but uhhh

#

sorry but um

#

i dont see how that parameter would work

#

I would attach all of them to it?

chilly quarry
#

what

#

you have that parametewr

analog quail
#

yes

chilly quarry
#

and after you instantiate it

#

you do ```cs
elementClone.GetComponent<compoundHandler>().element = element;

analog quail
#

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

chilly quarry
#

i dont really know

analog quail
#

maybe like

#

uhhh

#

hold on

#

I fell into my own confusion

chilly quarry
#

lol

analog quail
#

ok maybe just do a bunch of ifs idk

chilly quarry
#

ig

analog quail
#

so like

#
    public void cloneElement(elements element)
    {
      if (element.name == "Na") {
          elements element2 = elementClone.GetComponent<compoundHandler>().element;
      }
    }```
#

idk

chilly quarry
#

uh what

#

what is that supposed to do

analog quail
#

honestly

#

at this point

#

I don't know myself

chilly quarry
#

lmao

analog quail
#

Hold on let's get back to square one

chilly quarry
#

aight

analog quail
#

we use SO for info for elements right

chilly quarry
#

yes

analog quail
#

hmmmmm

#

Wait

#

would something like

#

element[_text] work

#

instead of the dot

#

for example

#

element["valance" + _text]

chilly quarry
#

i dont know what you're trying to do

#

with taht

analog quail
#

basically

#

to make everyone's lives easier

#

instead of making a SO for each element

#

we could like

chilly quarry
#

an array?

analog quail
#

make a db for the elements in a single SO

chilly quarry
#

uh

#

that doesn't sound very good

analog quail
analog quail
#

ughhh

#

hold on

#

so

#

after a button is pressed in a UI

#

It will instantiate a flask

chilly quarry
#

yes

analog quail
#

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

chilly quarry
#

i dont see the problem if you have multiple buttons

analog quail
#

except

#

how the [censorship] we do that

chilly quarry
#

well uh

#

you have a button called sodium for example

analog quail
#

yes

chilly quarry
#

and it calls the instantiate

#

and it has a parameter called element

analog quail
#

yes

chilly quarry
#

you just attach the SO that has info regarding sodium

#

where you call the function

analog quail
#

so

#

from what I understand

#

public void cloneElement(elements element)

cloneElement(elementClone.GetComponent<compoundHandler>().element);

chilly quarry
#

uh

#

you have something like this right

analog quail
#

because like honestly

#

yes

chilly quarry
#

and you have the instantiate whatever

#

it should have a parameter right next to the thing

analog quail
#

OH

chilly quarry
#

and that's where you attach the SO

analog quail
#

OHHHHHHHH

#

I DIDN'T THINK OF THAT

#

Like

#

I forgot about onclick

#

lol

chilly quarry
#

lol

analog quail
#

problem tho

#

void well

#

I need to put something in it

#

aka

chilly quarry
#

so, put something in it?

analog quail
#
    public void cloneElement(elements element)
    {

    }```
#

otherwise it will throw an error

chilly quarry
#

will it doe

#

it's a void

analog quail
#

yes

#

I tried

#

it did

#

scream

chilly quarry
#

damn

#

you mean like put some code in the function or

#

what

analog quail
#

" must declare a body because it is not marked abstract, extern, or partial"

chilly quarry
#

ah

#

show the code

analog quail
#

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);

    }```
chilly quarry
#

yes

analog quail
#

πŸ’€

chilly quarry
#

πŸ’€

analog quail
#

i love this community

chilly quarry
#

me too

analog quail
#

wait

#

what about the flask

#

😳

chilly quarry
#

what

analog quail
#

like

#

it needs to get cloned too

#

or smthng

chilly quarry
#

is it not cloned tho

analog quail
#

no

#

it gets cloned by that function

#

well

#

void

#

whatever

chilly quarry
#

just call it method

analog quail
#

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);

    }
}```
chilly quarry
#

didnt u already have it declared tho

analog quail
#

i did but the code itself is on the flask

#

so

#

it isnt on the button

#

wait

#

sudden realisation hits the fan

analog quail
#

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);```
chilly quarry
#

i mean

#

we are

#

setting the element

#

because it doesnt exist

analog quail
#

yes

chilly quarry
#

so you dont need to worry about that

analog quail
#

so I can remove it

chilly quarry
#

because what we wanna do is ```cs
elementClone.GetComponent<compoundHandler>().element = element;

analog quail
#

element = element seems like a bad idea

chilly quarry
#

they're different

#

elementClone.GetComponent<compoundHandler>().element and element are two different variables

analog quail
#

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?

chilly quarry
#

looks like it yeah

analog quail
#

IT WORKS

chilly quarry
#

YEAHHH!!!!1

analog quail
#

Thank you so much man

chilly quarry
#

np

analog quail
#

How much do I pay

chilly quarry
#

none

analog quail
#

u sure?

chilly quarry
#

yeh

analog quail
#

ok

#

tysm man

chilly quarry
#

np

analog quail
#

today I learned an important lesson

#

don't take drugs before work

chilly quarry
#

lol

analog quail
#

aight thanks man

#

goodnight!

chilly quarry
#

gn

analog quail
#

*good night!

#

wait actually one more thing

#

@chilly quarry

#

one more thing and I will leave you alone dw lol

chilly quarry
#

lol

#

whatis it

analog quail
#

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

chilly quarry
#

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

chilly quarry
#

right

analog quail
#

as I said

#

four employees

#

no proof of concept

#

need to prove this is possible

#

anyways

#

var myComponent = hitCollider.gameObject.GetComponent<compoundHandler>();

#

?

chilly quarry
#

ye

analog quail
#

and then

#

or something?

chilly quarry
#

myComponent.element i believe

analog quail
#

alright

#

yes

#

thank you so much

#

off to the cryonic station I go

#

to not be heared of in another 10 years

analog quail
#

@chilly quarry ok seriously one last thing

#

it shouldn't be difficult but uh

#

dk how to solve it

#

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

analog quail
#

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

graceful temple
#

what is it saying at line 41 and 72?

analog quail
graceful temple
analog quail
#

gimmie 44 minutes or so

#

*42

#

whatever

#

until 13:30

#

GMT +1

analog quail
#

Aight @graceful temple

#

im back

#

41: else

#

72:

#

nothing

analog quail
#

SO UM

#

@graceful temple

#

*so um

#

*caps

#

wait

#

it works now

#

aight

#

made a typo

#

πŸ’€

graceful temple
#

bruh

#

aight

#

then good job

analog quail
#

Aka

#

I written "l" instead of L

graceful temple
#

πŸ˜‚

analog quail
#

now its time to optimalize this...

#

um

#

abomination

#

I mean just look at it

graceful temple
#

yanderedev would be proud

analog quail
#

I want nothing to do with that scam

graceful temple
#

lmao

analog quail
#

anyways

graceful temple
#

i just mean all the if statements

analog quail
#

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

graceful temple
#

for sure

analog quail
#

so hmmm

#

how can I optimilize it

#

how do I write it the word I mean

graceful temple
#

let me have a look

analog quail
#

ok

#
  else
                        {
                            if (compoundData2.element.valance == 1)```
#

blood starts to boil

graceful temple
#

mhm

#

you cant really optimise this without redoing the whole thing

analog quail
#

as long as it'll still work I'm up for it

graceful temple
#

yea ik but i have no clue rn how

#

so what does it do

analog quail
#

so

graceful temple
#

and compoundData2

analog quail
#

this reads the name of the eleement

#

from SO

#
 var compoundData = hitCollider.gameObject.GetComponent<compoundHandler>();
            var compoundData2 = gameObject.GetComponent<compoundHandler>();```
graceful temple
#

compoundHandler() ?

#

ah wait i get it

analog quail
#
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;
}
graceful temple
#

actually idk at the moment

#

i dont quite understand the code since i structure mine different

#

you will have to do it yourselve

analog quail
#

alright