Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
18
Question by pkamat · Dec 01, 2009 at 01:41 PM · graphicsdecaloafa

Adding decals to a object

how do i add decals to a object? say i want to render bullet marks on a cube or wall.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ruben_hiet · May 15, 2011 at 11:42 AM 0
Share

is it possible to instentiate a projector on the position you hit an object and just project a texture of a bullet impact? I don't know anything about projectors but thought it is maybe possible?

avatar image AdamEstone · Aug 10, 2011 at 01:19 PM 0
Share

Why do i get this error when it collids?:

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

bullitHole.OnTriggerEnter (UnityEngine.Collider hit) (at Assets/bullitHole.js:3)

I used this code:

var bulletHole:GameObject;

function OnTriggerEnter( hit : Collider){

var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);

Instantiate(bulletHole, hit.point, hitRotation);

}

avatar image AdamEstone · Aug 10, 2011 at 01:25 PM 0
Share

Why do i get this error when it collids?:

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

bullitHole.OnTriggerEnter (UnityEngine.Collider hit) (at Assets/bullitHole.js:3)

I used this code:

var bulletHole:GameObject;

function OnTriggerEnter( hit : Collider){

var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);

Instantiate(bulletHole, hit.point, hitRotation);

}

4 Replies

· Add your reply
  • Sort: 
avatar image
27
Best Answer

Answer by duck · Dec 01, 2009 at 02:27 PM

The simplest way to achieve this would be to Instantiate a bullet-hole object at the point at which your bullet raycast hits the wall, and use the wall's normal for the object's rotation.

Something like this:

var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
Instantiate(bulletHole, hit.point, hitRotation);

However if you allow the creation of an unlimited number of bullet holes, this method might quickly start affecting performance. There are a number of ways of creating a more optimised 'decal' system, such as re-using a pool of decal objects.

Comment
Add comment · Show 10 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pkamat · Dec 02, 2009 at 09:33 AM 0
Share

Hello Duck, thanks you for the solution. This works great for flat surfaces but what if the surface is spherical and the decal is not a small bullet hole but say an big dark patch

avatar image duck ♦♦ · Dec 02, 2009 at 02:06 PM 0
Share

In that case, you'll need something much more complex. There's an article on the "wolfire" blog about projecting decals on to aribtrary geometry, which basically works by duplicating and cutting out the triangles from the mesh onto which the decal falls. You'd then want to render this cut-out piece of mesh using a decal shader which draws at a higher level in the draw queue, so there's no z-fighting with the underlying mesh. http://blog.wolfire.com/2009/06/how-to-project-decals/

avatar image pkamat · Dec 03, 2009 at 06:34 AM 0
Share

Thanks Duck, will try that approach

avatar image Khyrid_old · Dec 04, 2010 at 04:43 AM 0
Share

Duck I tried your code but it makes all the bullet hole objects 90 degrees the wrong direction.

avatar image cormac · May 06, 2011 at 03:57 PM 1
Share

try Vector3.forward ins$$anonymous$$d of vector3.up

Show more comments
avatar image
9

Answer by Ashkan_gc · Dec 01, 2009 at 02:29 PM

currently decal rendering is not supported in unity. vote for this in feedback http://feedback.unity3d.com/pages/15792-unity however you can easily draw a texute on another with getpixels and setpixels functions of Texture2D class. you can draw bullet texture easily on the wall. you should not use the sharedmaterial and should use the material property to get textures. if you use sharedmaterial the real asset file and all other gameobjects using the texture/material will change. you should get the UV cords of a raycast from Raycasthit object in raycasts. in collisions and functions like OnTriggerEnter or ... you can cast a ray from the bullet's position and in it's movement direction and see where it will collide to the other collider. you should disable the raycast for the bullet itself

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SinisterRainbow · Dec 08, 2013 at 06:04 AM 1
Share

this link no longer exists.. Was it axed or did it make it's way into 4.0 and I haven't done due diligence in finding it? I'd rather not do middleware system stuff if it's going in later, this seems like it's one that should eventually make it, just too many people would use it.

avatar image Dantus · Dec 12, 2013 at 09:55 PM 0
Share

It is just a broken link which brought you to this page: http://feedback.unity3d.com/suggestions/graphics-decal-system?page=1

You may think about using that one: https://www.assetstore.unity3d.com/#/content/3779

avatar image
2

Answer by SneezingCatP · Apr 01, 2012 at 02:21 AM

I wrote my decal script into the FPS tutorial mating gun script here it is

add this to the variables

var BulletTexture : GameObject;

add this to the hit particles section

clone = Instantiate(BulletTexture, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); Destroy(clone.gameObject, 5); clone.transform.parent = hit.transform;

it will parent the decal object with whatever it hits then deletes it after 5 seconds

Dj

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Khyrid_old · Nov 21, 2010 at 01:09 PM

I've tried a lot to get this to work but I can't figure it out. Where do I put the code? In the gun or the bullet object? I tried with putting it in the bullet and what I got was a string of bullethole objects on the ground between me and the direction I was shooting. I have no idea what I'm doing.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Delete a Decal Projector at Runtime 0 Answers

HDRP Decal Projector doesn't show in game view 0 Answers

LWRP - Placing markers on terrain and gameobject dynamically 0 Answers

Eliminate start up dialog? 1 Answer

Alt+Tab issue in fullscreen? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges