#Examine System
1 messages · Page 1 of 1 (latest)
hey so
look on your player's root object possibly. there must be a script that modifies references of your iteminfo class
Start from going to the asset page and reading on how to use it.
yeah also showing us what the asset is would be handy
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
There seems to be a documentation file in the asset folder. Open it and start reading.
Alright. Then according to the docs, what affects the zoom?
are your spawned prefabs in the examinable layer?
Okay. Now compare these parameters between the object that the zoom works for and the one that doesn't.
do they have box colliders on them
Yep
They're the same
I've tried with and without
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
can you post the code for both iteminfo and ultimateexaminesystem
alright
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
This is the item info
Alright
a powerful website for storing and sharing text and code snippets. completely free and open source.
thx. i'm more interested in seeing the brain script though. because that's the thing that's responsible for actually inspecting the items
a powerful website for storing and sharing text and code snippets. completely free and open source.
the thing that's cool about pastemyst btw, if you click "add pasty" it'll let you post multiple scripts on the same link
ohh
okay so you see this line?
mhm
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
Okay one sec
you can take multiple screenshots if you cant get them all in one view
so the radius on that sphere collider looks a little sus
can you show me the radius in relation to the object
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
the cube?
oh nvm i'm dumb. it's doing a raycast
hold on imma edit this script so you can get more information
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
is it because these are models?
what do you mean
i don't know what you're asking
are models and prefabs different?
can you show me what you're talking about
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
Hm wdym?
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
can you show me though
okay
i dragged the model outside of the
other prefabs
and it works
so i think the problem is that prefabs wont work
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
k
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
arrow
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
oh
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
huh
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
ohhh
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
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
oh
alright
but the kettle inside the map
is still not working
only the one outside the map
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
a powerful website for storing and sharing text and code snippets. completely free and open source.
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
yes
oh sorry
double click that error and modify the line to
hit.collider.gameObject
instead of hit.gameObject
can you show me that line of code. that's interesting lol
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
so you're not detecting the kettle in the asylum
it's just detecting the asylum itself
i think i saw something in the script sec
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
is your asylum on the examinable layer
its on default
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
okay so it's detecting them that's good. you're saying the kettle that's in the asylum prefab just isnt zoomable tho?
yes
what happens? can you press E and it does anything?
can you rotate it or anything like that?
nope
a powerful website for storing and sharing text and code snippets. completely free and open source.
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
how?
nvm
got it
okay so we know handledetectionUi is being called that's nice
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
yeah
you didn't try to enter examine state on any of them?
you get "ExamineStateEnter" in the console for all of them?
wwait
and when you press E even on the one that works, does it lock your movement like the others
where do you think
yes. beyond that though
where does it hint that the problem lies
it has to be something to do with the model itself
your script is treating these two objects somehow differently
you need to figure out HOW that is happening
hm
hm
is it detecting the zoom and rotate
but we dont know how the other objects detect it
okay you're either overthinking this at all or (i hope not) gaming me lol
here's a hint
what does this line tell you about what we know is happening
its examining the object
but it's not right
which means we're getting INTO the examine method and THEN something is going wrong
so the examine function is wrong?
which tells you the problem is likely where?
the function isn't necessarily wrong
it's doing something we don't expect
so what do we need to do
find out where it derails
cool. how
what have i been doing
ayyyyyyy!
to detect zoom
that sounds awesome
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
maybe when its getting the input or getting the item position
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
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);
}
}```
try to pick a smaller chunk
is it in that vicinity>
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
zoomDistance = Vector3.Distance(cam.position + cam.forward, hit.point); //sets zoom distance to the point where the collision was detected
is the code deciding anything there?
not rlly i guess
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
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
into the object
that gives you opportunity to behave differently when you get to the store, based on what happens

especially raycasts, because the script can't control what we're looking at, so its a very contextual moment in code
ahhh i see
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
uh
what i can think of right off the bat
- did we hit anything at all?
- if we did, which object was it?
- what is the zoomDistance value after we perform the raycast
hm
but since we detect the object
and it examines
plus the cursor changes colour
this is a different raycast from the object detection raycast
this is checking for collisions
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
i tried unpacking the asylum
thats just a theory though
I would also debug the zoomDistance before and after clamp
hmm ok
so i just
unpacked the asylum object
and then moved it out of asylum
but still nothinh
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
i undo'd everything
i was just testing
my thinking is something is causing your zoomDistance to be set to like nothing
so it's "zooming" just between 0 and 0
negative
im not too sure what it actually signifies
that value lets you manually determine the min/max zoom. but if not it sets it to 0.9/2
do i go into examine again?
what do you mean go into
you replace examine with the code i just gave you and run it again yeah
yes
see what happens differently if anything between the working and non working objects
what do you mean off by one
i still don't know what off by one means
the zoom distance value
wait nevermind
the zoom distance depends on how far away you are from the object when you click on it
yes
so on the one that's NOT working
it's just stuck at that value regardless of what you do?
the zoomDistance refers to the distance from the camera
it starts from 0.3
the minmax zoom distance is the minimum and maximum distance from the camera
i know
0.8 when u go even closer
it increases for some reason??
and the mouse wheel has no effect ofc
that happens for all of them?
let me make sure
not rlly
the other kettle is at
0.3
at this distance
the cube is at around 0.2
did you check teh difference between things that are being hit by the collision detection
"Collision detected on zoom..."
im not too sure how to check that
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
oh wait
it should SHOW IT in the log
you need to see if it's different for the objects that work and dont
so comment out the stuff you're not using
ah ok yeah
both working ones
detect no collisions
so the kettle is detecting a collision
the non working one that is
so the kettle is colliding with "collider placeholder"
what does that make you think
search for that value in the script
yep
is it the localScale?
yeah
think about your problematic kettle. remember i said it has a different scale than the working stuff
you scaled it up to look normal in the world, but the collider that this script generates scales to match the object
ahhh
can you show me the whole heirarchy of the kettle in the prefab
one of its parents is probably scaled-down and you're scaling up to compensate
either gatehouse or 1st floor or asylum itself
gatehouse is
there's your problem then
so there's no reason for the actual gatehouse mesh to be the parent of the kettle
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
remember when i told you to edit the prefab itself
not the instance
unity is telling you not to edit the prefab instance
wb?
what about
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 
this developer, based on his code though
is extremely halfassed and messy
i would think twice about buying other packages from them lol
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
alright gj