Object Inspector

Enhance item viewing experience in your games with smooth 3D rotation using the mouse cursor.

Applications

  • Ingame achievement display
  • Shop menu
  • Puzzle/escape room games

Installation

  1. Under the Community tab
  2. Search for “Object Inspector”
  3. Install the package called Object Inspector by itsjacky7

How To Use

  1. After installing the package you will find 2 templates
    • objectInspectorView
    • objectInspector

  2. Attach the objectInspectorView to the User template

    object inspector view hierarchy

  3. Add the objectInspector somewhere in your game world
  4. Add the object you want to inspect as a child of the objectContainer locator

    object inspector hierarchy

  5. Preview the game, walk up to the object inspector trigger and press the interact button to activate the object inspector.
  6. Use the mouse cursor to click and drag to rotate the object.
  7. Use the mouse wheel to zoom the camera in and out.

Properties

objectInspectorView

  • Show UI

    • Displays the default object inspector UI. Uncheck this property if you want to integrate your own UI.
  • Name Size

    • Sets the font size (rem) of the object name in the default object inspector UI.
  • Description Size

    • Sets the font size (rem) of the object description in the default object inspector UI.

objectInspector

  • id

    • Unique identifier for the object inspector.
  • objectName

    • The name of the object to be displayed in the object inspector UI.
  • objectDescription

    • The description of the object to be displayed in the object inspector UI.
  • cameraTransitionTime

    • Time in seconds (s) that the player camera takes to transition into the object inspector camera.
  • rotationSpeed

    • Speed in which the inspected object is rotated (using mouse click and drag).
  • rotationDamping

    • This controls how smooth the object rotation is.
  • rotation3D

    • If enabled the inspected object can be rotated in all 3 dimensions. If disabled, the object can only rotatate along the Yaw axis.
  • zoomSpeed

    • Speed in which the camera zooms in/out (using mousewheel).
  • zoomDamping

    • This controls how smooth the zoom is.
  • zoomInDistance

    • The amount distance that the camera can zoom in from the default position.
  • zoomOutDistance

    • The amount distance that the camera can zoom out from the default position.

Example Application

In this example we implement a simple interaction using the object inspector that could be used in puzzle/escape room style games.

In the objectInspectorViewScript you will find the below function which triggers on mouse click when the object inspector is active.

function ObjectInspectorViewScript:OnObjectInspectorClick(hitResult)
	-- This function can be used to implement user interactions in the object inspector (see package guide on the forum for an example).
end

We can use this function to add user interactions to the object inspector.

For this example we used a Jewelled Skull object and hid a Coin under it for the player to find.

Then update the OnObjectInspectorClick function with the below code:

function ObjectInspectorViewScript:OnObjectInspectorClick(hitResult)
	if self:GetEntity():IsLocal() then
		local cursorPosition, cursorTarget = self:GetEntity():GetCursorLookAt()
		GetWorld():Raycast(cursorPosition, cursorTarget, {self.inspectorProperties.trigger}, function(hitEntity, hitResult)
			if hitResult then
				if hitEntity:GetName() == "coin" then
					hitEntity.visible = false
					self:GetEntity():PlaySound2D(self.properties.collectSound)
				end
			end
		end)
	end
end

Thanks to Daigoro for informing me about the GetCursorLookAt() function.

The code casts a Raycast from the cursor position into the world when the mouse is clicked. It then checks if the entity that is hit by the raycast has the name “coin”. In this example we simply hide the coin and play a sound but this could be further expanded in your own game.

The final results for this example:

5 Likes

I love that. I will use it.

1 Like

Finding the coin is really cool :slight_smile:

1 Like