#Examine System

1 messages · Page 1 of 1 (latest)

gusty heron
#

Hello

torpid dagger
#

hey so

#

look on your player's root object possibly. there must be a script that modifies references of your iteminfo class

young pulsar
#

Start from going to the asset page and reading on how to use it.

torpid dagger
#

yeah also showing us what the asset is would be handy

gusty heron
#

oh

#

youtube links arent allowed?

#

theres a youtube tutorial attached in the docs which is what ive been using

#

dont think there should be a problem with setup since the cube object works

young pulsar
#

There seems to be a documentation file in the asset folder. Open it and start reading.

gusty heron
young pulsar
#

Alright. Then according to the docs, what affects the zoom?

gusty heron
torpid dagger
#

are your spawned prefabs in the examinable layer?

young pulsar
#

Okay. Now compare these parameters between the object that the zoom works for and the one that doesn't.

torpid dagger
#

do they have box colliders on them

gusty heron
torpid dagger
#

can you post a link to your item info class in here

#

i like paste.myst.rs because you can post multiple scripts in one link

gusty heron
#

Should I download a random model

#

and see if it works

torpid dagger
#

can you post the code for both iteminfo and ultimateexaminesystem

gusty heron
#

alright

torpid dagger
#

i'm wondering if that class finds all item info components in the scene on awake and just works off that, which could make spawned prefabs not ever get added

#

can you please use paste links

gusty heron
#

This is the item info

#

Alright

torpid dagger
#

thx. i'm more interested in seeing the brain script though. because that's the thing that's responsible for actually inspecting the items

gusty heron
torpid dagger
#

the thing that's cool about pastemyst btw, if you click "add pasty" it'll let you post multiple scripts on the same link

gusty heron
#

ohh

torpid dagger
#

okay so you see this line?

gusty heron
#

mhm

torpid dagger
#

what that's doing is a raycast in front of the camera and then storing off the detected item it hits and then manipulating it

#

this is the most likely culprit it seems to me, so we need to double check several things:

  • we need to make sure that the object we want to hit is on the appropriate layer that the raycast is firing on
  • we need to make sure that the object has either a mesh+meshcollider, or a box/capsule/etc collider
  • that collider is ENABLED
#

can you show me a screenshot of an instantiated prefab's components

gusty heron
#

Okay one sec

torpid dagger
#

you can take multiple screenshots if you cant get them all in one view

gusty heron
#

seems to be fine

torpid dagger
#

so the radius on that sphere collider looks a little sus

gusty heron
#

hmm?

#

what should it be?

torpid dagger
#

can you show me the radius in relation to the object

gusty heron
#

its a kettle

torpid dagger
#

because my assumption is the sphere collider (which is a trigger) is what's used to determine proximity for interactability

#

can you show me a non-prefab object

#

it should have two colliders as well. i'm interested in the one that's a trigger

gusty heron
#

the cube?

torpid dagger
#

srue

#

whichever one you have in yoru scene that works as intended

gusty heron
#

it only has

#

a box collider

torpid dagger
#

oh nvm i'm dumb. it's doing a raycast

#

hold on imma edit this script so you can get more information

gusty heron
#

Ayo dont call yourself dumb

#

Makes me worse

#

;(

torpid dagger
#

lol sorry that's just my shorthand for saying i led myself down a wrong thought path

#

lemme tweak this quick and then you can get a lot more introspection as to what's happening in your script

gusty heron
#

Okay ty

#

I imported a random prefab

#

and it worked with that

torpid dagger
#

oh interesting

#

what are the differences

gusty heron
#

is it because these are models?

torpid dagger
#

what do you mean

gusty heron
#

like

#

the kettle

torpid dagger
#

i don't know what you're asking

gusty heron
#

are models and prefabs different?

torpid dagger
#

can you show me what you're talking about

gusty heron
torpid dagger
#

can you show me a side-by-side of how you're using both of those

#

i think you did before but it was a lot of pics all at once so i didn't look too closely

gusty heron
#

Hm wdym?

torpid dagger
#

prefabs are already pre-defined gameobjetcs. when you drag a model into a scene, it sort of imports it as a basic gameobject with just like a mesh and nothing else

#

drag the kettle and the prefab that worked into the scene

#

take screenshots of their inspectors side-by-side. show me how they look in the scene hierarchy on the left as well as their components

gusty heron
#

the only difference i see is

#

that they're prefabs

torpid dagger
#

can you show me though

gusty heron
#

oh shoot

#

i got it working

#

not that specific model though

torpid dagger
#

okay

gusty heron
#

i dragged the model outside of the

#

other prefabs

#

and it works

#

so i think the problem is that prefabs wont work

torpid dagger
#

so i would recommend you do this with your models btw

#

don't fuck with them directly, because when you drag them into a scene they're going to be freshly imported every time as like a new prefab. if you create prefabs for them, then you can pre-configure them to work properly

gusty heron
#

i do have a question thi

#

tho

torpid dagger
#

k

gusty heron
#

how do i like

#

edit stuff in this

#

u see the 'asylum'

torpid dagger
#

yeah

#

so you can do it one of two ways

#

you can find the prefab itself in your project view and double click it to go to prefab edit mode

#

OR

#

you see this

#

if you click that, it'll open up a context-edit mode, where you can see the prefab normally, but everything apart from it will be greyed out

#

that way you can edit the prefab to see how it fits in your world

gusty heron
#

oh

torpid dagger
#

but since your prefab basically IS the world it probably doesn't matter

#

also i would recommend making sure you click the "overrides" drop down and hit "revert all" since you want the prefab itself to be edited, not he prefab instance

#

if that makes sense

gusty heron
#

huh

torpid dagger
#

say i have a prefab of a person right

#

and i instantiate like twenty of them

gusty heron
#

oh this

torpid dagger
#

if i modify one of them to have red hair, it will now be different because i only changed the instance

#

and if i go into the prefab editor mode and change the hair to black, ALL the prefab instances (except the ones that already have modified hair) will now be black haired

gusty heron
#

ohhh

torpid dagger
#

and if i do override->revert all on the redhead, he'll have black hair now

#

because you're reverting him to the prefab default

gusty heron
#

wait wtf

#

i hit revert all

#

and a lot of stuff is weird now

torpid dagger
#

oh, ctrl+z

#

you had a LOT of changes in that lol

#

if you WANT those changes to apply to the prefab, you need to do overrides->apply all

#

what that does is make your instance's current state the authority for all asylum prefabs

gusty heron
#

oh

#

alright

#

but the kettle inside the map

#

is still not working

#

only the one outside the map

torpid dagger
#

you have to show me the difference between the kettle and a working object

#

oh

#

that's perfect

#

show me the kettle instances inside and outside the map

gusty heron
#

okay

#

outside the map

#

inside the map

torpid dagger
#

try this script and tell me what the debug console is showing when you point at things that work vs things that don't

#

it should log the item that you're detecting to the console if/when you are detecting it

gusty heron
#

oh i missed this

#

this is with the ultimateexaminesystem right

torpid dagger
#

yes

gusty heron
#

hm

torpid dagger
#

oh sorry

#

double click that error and modify the line to

#
hit.collider.gameObject
#

instead of hit.gameObject

gusty heron
#

hmmmm

torpid dagger
#

can you show me that line of code. that's interesting lol

gusty heron
#

it recognises it

#

which line?

torpid dagger
#

show me what you wrote

#

the one you edited

gusty heron
torpid dagger
#

they're not just called gameobject in the scene are they?

#

that's super weird

gusty heron
#

hmm

#

both seem to be the same output

torpid dagger
#

can you search in your scene view for just "gameObject" and show me what it filters out

#

or better yet, sec

#
Debug.Log($"Detected object: {nameof(hit.collider.gameObject)}", hit.collider.gameObject);
#

modify the line to do this

#

that will allow you to highlight the object when you click on the log

#

so we can see whats actually being hit

gusty heron
torpid dagger
#

so you're not detecting the kettle in the asylum

#

it's just detecting the asylum itself

gusty heron
#

yep

#

im pretty sure thats exactly whats happening

#

especially since

torpid dagger
#

i think i saw something in the script sec

gusty heron
#

when you click on the object in the scene

#

it first shows up as asylum

#

and then you have to click it again

#

to show the actual kettle

torpid dagger
#

is your asylum on the examinable layer

gusty heron
#

its on default

torpid dagger
#

oh sec hold on i'm dumb

#
Debug.Log($"Detected object: {hit.collider.gameObject.name}", hit.collider.gameObject);
#

try that instead

#

nameof gives you the variable name not the gameobject name

gusty heron
#

oh

#

i also need help with smth else btw

#

the kettle is being detected

torpid dagger
#

okay so it's detecting them that's good. you're saying the kettle that's in the asylum prefab just isnt zoomable tho?

gusty heron
#

yes

torpid dagger
#

what happens? can you press E and it does anything?

gusty heron
#

yes

#

it just doesnt zoom in

torpid dagger
#

can you rotate it or anything like that?

gusty heron
#

nope

torpid dagger
#

try this. i just added a lot of debug statements. while you're debugging, turn off the "collapse messages" option so you can see the order that they happen in

#

that'll probably give some insight into what the script is doing

torpid dagger
#

okay so we know handledetectionUi is being called that's nice

gusty heron
#

the ui works

#

the zoom and rotation doesnt

torpid dagger
#

change HandleDetectionUI to this

#
void HandleDetectionUI(GameObject item, bool detected) { //disable/enable detectuin UI
        Debug.Log("HandleDetectionUI");
        if (detected && detectionStateChange) //if examinable object has been detected
        {
            detectedItem = item.transform;  //store detected item reference
            Debug.Log($"Detected item stored: {detectedItem.gameObject.name}");

            cursorDot.color = cursorDotHighlighted; //set cursor highlight color
            detectCanvas.enabled = true;

            try //set item name UI text to UI text
            {
                _itemName.text = item.GetComponent<ItemInfo>().GetName();
            }
            catch { //if item object doesnt have ItemInfo script attached
                _itemName.text = "Unknown item";
                Debug.LogWarning(item.name + " does not have ItemInfo component!");
            }

        }
        else if(detectionStateChange){ //disable UI, set normal cursor color
            cursorDot.color = cursorDotDefaultColor;
            detectCanvas.enabled = false;
        }
    }
#

you see the process of what i'm doing though? just like finding hints and seeking further info

gusty heron
#

yeah

torpid dagger
#

you didn't try to enter examine state on any of them?

gusty heron
#

oh

#

shoot

#

they all say the same thing

#

"Examing..."

torpid dagger
#

you get "ExamineStateEnter" in the console for all of them?

gusty heron
#

Examining

torpid dagger
#

turn collapse back on

#

do you see examinestateenter for all of them

torpid dagger
#

and when you press E even on the one that works, does it lock your movement like the others

gusty heron
#

where?

#

where do i put that block

torpid dagger
#

where do you think

gusty heron
#

it wasnt showing up in find

#

weird

torpid dagger
#

ok so what does this tell you

#

i can't do every step of this for you lol

gusty heron
#

everything is being detected

#

its detecting the ui

#

the item

torpid dagger
#

yes. beyond that though

gusty heron
#

and the examine state

#

uh

torpid dagger
#

where does it hint that the problem lies

gusty heron
#

it has to be something to do with the model itself

torpid dagger
#

your script is treating these two objects somehow differently

#

you need to figure out HOW that is happening

gusty heron
#

hm

torpid dagger
#

where in the script do you think we need to look

#

to find that discrepancy

gusty heron
#

the place where it detects the gameobject?

#

to see what parameters it sets?

torpid dagger
#

we already confirmed they're both being detected

#

the problem isn't there

gusty heron
#

hm

torpid dagger
#

based on what you see by the debug statements

#

where do you KNOW we're getting to

gusty heron
#

is it detecting the zoom and rotate

#

but we dont know how the other objects detect it

torpid dagger
#

okay you're either overthinking this at all or (i hope not) gaming me lol

#

here's a hint

gusty heron
#

might be why

torpid dagger
#

what does this line tell you about what we know is happening

gusty heron
#

its examining the object

torpid dagger
#

but it's not right

#

which means we're getting INTO the examine method and THEN something is going wrong

gusty heron
#

so the examine function is wrong?

torpid dagger
#

which tells you the problem is likely where?

gusty heron
#

for the specific object

#

in the examine settings?

torpid dagger
#

the function isn't necessarily wrong

#

it's doing something we don't expect

#

so what do we need to do

gusty heron
#

find out where it derails

torpid dagger
#

cool. how

gusty heron
#

either trial and error orrr

#

uh

torpid dagger
#

what have i been doing

gusty heron
#

checking what is actually happening

#

oh

#

add in more debug statements?

torpid dagger
#

ayyyyyyy!

gusty heron
#

to detect zoom

torpid dagger
#

that sounds awesome

gusty heron
#

and

#

other stuff?

torpid dagger
#

so we know something is going wrong inside the Examing() method, which really narrows our focus

#

looking at the code, can you identify some points where it might derail and cause us problems? and being able to see that information might be illuminating?

#

i can think of two off the bat

gusty heron
#

maybe when its getting the input or getting the item position

torpid dagger
#

well one specifically

#

show me the most suspicious chunk of code in your opinion

#

aka the thing that NEEDS to happen for zooming to work

#

something that isn't guaranteed to work

gusty heron
#
            float temp = zoomDistance;
            float input = Input.GetAxis("Mouse ScrollWheel");
            RaycastHit hit;
            if (Physics.Raycast(cam.position, detectedItem.position - cam.position, out hit, zoomDistance + input + collisionCheckDistance) && !hit.transform.IsChildOf(detectedItem)) //if new position would collide do this
            {
                zoomDistance = Vector3.Distance(cam.position + cam.forward, hit.point); //sets zoom distance to the point where the collision was detected
            }
            else { //if new position wouldn't collide, freely change according to player input
                zoomDistance += input;
            }

            zoomDistance = Mathf.Clamp(zoomDistance, zoomMinMax.x, zoomMinMax.y); //clamp current zoom distance to min/max limits 

            detectedItem.position = Vector3.Lerp(detectedItem.position, cam.transform.position + cam.forward * zoomDistance, zoomSmoothness * Time.deltaTime); //smoothly zoom by moving an objects closers/farther from the camera

            //handle dynamic depth of field
            _volume.profile.TryGetSettings<DepthOfField>(out var DOF);
            DOF.focusDistance.value = Vector3.Distance(cam.position, detectedItem.position);
        }
    }```
torpid dagger
#

try to pick a smaller chunk

gusty heron
#

is it in that vicinity>

torpid dagger
#

yes

#

don't overthink it

#

variability in code happens most often when decisions are made

#

what does a decision look like in code

#

or rather a choice

gusty heron
#

zoomDistance = Vector3.Distance(cam.position + cam.forward, hit.point); //sets zoom distance to the point where the collision was detected

torpid dagger
#

is the code deciding anything there?

gusty heron
#

not rlly i guess

torpid dagger
#

sure

#

so

gusty heron
#

this feels like school

#

detectedItem.position = Vector3.Lerp(detectedItem.position, cam.transform.position + cam.forward * zoomDistance, zoomSmoothness * Time.deltaTime); //smoothly zoom by moving an objects closers/farther from the camera maybe this since its the script where its actually zooming the camera

torpid dagger
#

if i tell you to go to the store and buy me some eggs, and if they have the kind i like, get me two dozen, otherwise get me one dozen of the store brand

gusty heron
#

into the object

torpid dagger
#

that gives you opportunity to behave differently when you get to the store, based on what happens

gusty heron
#

ohhh

#

OHHHH

#

so the if statement?

torpid dagger
gusty heron
#

NO WAYYY

#

holy fucking shit

torpid dagger
#

especially raycasts, because the script can't control what we're looking at, so its a very contextual moment in code

gusty heron
#

ahhh i see

torpid dagger
#

which makes it BIG SUSSY

#

so what information do you think we can get in this raycast section that might tell us whats going on

gusty heron
#

uh

torpid dagger
#

what i can think of right off the bat

#
  1. did we hit anything at all?
  2. if we did, which object was it?
  3. what is the zoomDistance value after we perform the raycast
gusty heron
#

hm

#

but since we detect the object

#

and it examines

#

plus the cursor changes colour

torpid dagger
#

this is a different raycast from the object detection raycast

gusty heron
#

doesnt it mean that it detects our input on the object

#

oh

torpid dagger
#

this is checking for collisions

gusty heron
#

ohh

#

right

#

dif sections

torpid dagger
#

what i'm automatically suspicious of out the gate

#

your asylum object is scaled, which means the scale factor of your children are compensating for that fact. so you could theoretically be projecting much larger raycast distances on your childed object, which means that it could be firing a ray directly into the object you're trying to pick up and considering it a collision

gusty heron
#

i tried unpacking the asylum

torpid dagger
#

thats just a theory though

#

I would also debug the zoomDistance before and after clamp

gusty heron
#

hmm ok

#

so i just

#

unpacked the asylum object

#

and then moved it out of asylum

#

but still nothinh

torpid dagger
#

well

#

why would you change that at this moment lol

#

that's introducing more variables before we even figured out wtf is going on

#
void Examine() {
        Debug.Log("Examining...");
        if (Input.GetKeyDown(KeyCode.E)) //Stop examining
        {
            ExamineStateLeave();
        }
        else {
            if (Input.GetKey(KeyCode.Mouse1)) //rotate the object if input detected
            {
                float rotX = Input.GetAxis("Mouse X") * rotationSpeed;
                float rotY = Input.GetAxis("Mouse Y") * rotationSpeed;

                detectedItem.Rotate(cam.up, -rotX, Space.World);
                detectedItem.Rotate(cam.right, rotY, Space.World);
            }

            if (hasInterestPoints) DetectInterestPoints(); //look for interest points

            //Check for collisions when zooming an item
            float temp = zoomDistance;
            float input = Input.GetAxis("Mouse ScrollWheel");
            RaycastHit hit;
            if (Physics.Raycast(cam.position, detectedItem.position - cam.position, out hit, zoomDistance + input + collisionCheckDistance) && !hit.transform.IsChildOf(detectedItem)) //if new position would collide do this
            {
                Debug.Log($"Collision detected on zoom: {hit.collider.gameObject}");
                zoomDistance = Vector3.Distance(cam.position + cam.forward, hit.point); //sets zoom distance to the point where the collision was detected
            }
            else { //if new position wouldn't collide, freely change according to player input
                Debug.Log("No Collision Detected on zoom");
                zoomDistance += input;
            }

            Debug.Log($"Zoom Distance: {zoomDistance}");
            zoomDistance = Mathf.Clamp(zoomDistance, zoomMinMax.x, zoomMinMax.y); //clamp current zoom distance to min/max limits 
            Debug.Log($"Clamped Zoom Distance: {zoomDistance}");

            detectedItem.position = Vector3.Lerp(detectedItem.position, cam.transform.position + cam.forward * zoomDistance, zoomSmoothness * Time.deltaTime); //smoothly zoom by moving an objects closers/farther from the camera

            //handle dynamic depth of field
            _volume.profile.TryGetSettings<DepthOfField>(out var DOF);
            DOF.focusDistance.value = Vector3.Distance(cam.position, detectedItem.position);
        }
    }
#

modify your examine method to that

gusty heron
#

i was just testing

torpid dagger
#

my thinking is something is causing your zoomDistance to be set to like nothing

#

so it's "zooming" just between 0 and 0

gusty heron
#

hm

#

0 - 0 should be the default value

torpid dagger
#

negative

gusty heron
#

im not too sure what it actually signifies

torpid dagger
#

if it's 0-0 it should be replacing it with these values

gusty heron
#

i meant

#

in the inspector

torpid dagger
#

right

#

we don't care about the inspector

#

for this

gusty heron
#

signifies

torpid dagger
#

that value lets you manually determine the min/max zoom. but if not it sets it to 0.9/2

gusty heron
#

do i go into examine again?

torpid dagger
#

what do you mean go into

#

you replace examine with the code i just gave you and run it again yeah

gusty heron
#

like examine mode

#

in game

torpid dagger
#

yes

#

see what happens differently if anything between the working and non working objects

gusty heron
#

the zoom value

#

is off by 1

torpid dagger
#

what do you mean off by one

gusty heron
#

wait

#

the other objects zoom in close to a value of 1

#

but this one is different

torpid dagger
#

i still don't know what off by one means

gusty heron
#

the zoom distance value

torpid dagger
#

right but

#

how is 0.3 off by one

#

what do you mean when you say that

gusty heron
#

wait nevermind

#

the zoom distance depends on how far away you are from the object when you click on it

torpid dagger
#

yes

#

so on the one that's NOT working

#

it's just stuck at that value regardless of what you do?

gusty heron
#

its actually giving different values for some reason

#

its kinda confusing

torpid dagger
#

the zoomDistance refers to the distance from the camera

gusty heron
#

it starts from 0.3

torpid dagger
#

the minmax zoom distance is the minimum and maximum distance from the camera

gusty heron
#

u go closer it goes to 0.04

#

then it goes to

torpid dagger
#

i know

gusty heron
#

0.8 when u go even closer

#

it increases for some reason??

#

and the mouse wheel has no effect ofc

torpid dagger
#

that happens for all of them?

gusty heron
#

let me make sure

#

not rlly

#

the other kettle is at

#

0.3

#

at this distance

#

the cube is at around 0.2

torpid dagger
#

did you check teh difference between things that are being hit by the collision detection

#

"Collision detected on zoom..."

gusty heron
#

im not too sure how to check that

torpid dagger
#

you're obsessing over the distance values of objects with different scales

#

WHAT DO YOU MEAN lol

#

i hand held you through the entire logical process of debugging and gave you the code to log those values

gusty heron
#

oh wait

torpid dagger
#

it should SHOW IT in the log

gusty heron
#

too much stuff

#

i couldnt see

#

i had to search for it

#

2 instances found

torpid dagger
#

you need to see if it's different for the objects that work and dont

gusty heron
#

theres too much stuff in the console tho

#

ill just limit it

torpid dagger
#

so comment out the stuff you're not using

gusty heron
#

ah ok yeah

#

both working ones

#

detect no collisions

#

so the kettle is detecting a collision

#

the non working one that is

torpid dagger
#

so the kettle is colliding with "collider placeholder"

#

what does that make you think

#

search for that value in the script

gusty heron
#

yep

torpid dagger
#

the answer is like three lines away

#

do you see it

gusty heron
#

is it the localScale?

torpid dagger
#

yeah

#

think about your problematic kettle. remember i said it has a different scale than the working stuff

gusty heron
#

cuz of the objec

#

t

#

the asylum object

torpid dagger
#

you scaled it up to look normal in the world, but the collider that this script generates scales to match the object

gusty heron
#

ahhh

torpid dagger
#

can you show me the whole heirarchy of the kettle in the prefab

gusty heron
torpid dagger
#

one of its parents is probably scaled-down and you're scaling up to compensate

#

either gatehouse or 1st floor or asylum itself

gusty heron
#

gatehouse is

torpid dagger
#

there's your problem then

gusty heron
#

0.2026508

#

do i make it 1?

#

or

#

will that break it

torpid dagger
#

so there's no reason for the actual gatehouse mesh to be the parent of the kettle

gusty heron
#

ok i see it now

#

the kettle is

#

4.934599

torpid dagger
#

i would say modify your structure so you have a "gatehouse" object that's completely empty, scale 1:1:1, and the gatehouse mesh would be a child of it, with no children, scaled to the value you need

#

so it's not fucking the scale of everything else

gusty heron
torpid dagger
#

remember when i told you to edit the prefab itself

#

not the instance

#

unity is telling you not to edit the prefab instance

gusty heron
#

oh yeah

#

true

#

and then wb the other objects?

torpid dagger
#

wb?

gusty heron
#

what about

torpid dagger
#

well clearly this package you're using is fucked for anything that doesn't have an absolute world scale of 1:1:1

#

so just make sure anything you want to be examinable has a Vector3.one scale and all of its parents do as well

#

unless you want to refactor the package to be completely scale-able but i assume not

#

this is a lot less work

#

and we use packages to avoid work KEKW

gusty heron
#

ture

#

true

torpid dagger
#

this developer, based on his code though

#

is extremely halfassed and messy

#

i would think twice about buying other packages from them lol

gusty heron
#

i dont usually buy packages

#

this was one of the only ones i could find for an examine system

#

that looked good

#

it was only like $7 anyways

#

ok im gonna head to sleep

#

its 5 am

#

ty for the help

torpid dagger
#

alright gj