Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by AmazingMrBrock · Jul 01, 2015 at 07:13 PM · c#component

Trying to make a dynamic error logging class, running into some trouble

I want to pass the gameobject, and the current component into the error logger and have it print out some debug.log.

Here's what I currently have for the error logger:

 public class ErrorLog : MonoBehaviour {
 
     public ErrorLog(){
     }
 
     public ErrorLog(GameObject relevantObject, objectrelevantComponent, string methodName, string additionalInfo){
         Debug.Log ("<----------- ERROR MESSAGE ----------->");
         string gOName = relevantObject.name.ToString();
         string cOName = relevantComponent.GetType().Name;
         string timeStamp = Time.time.ToString();
         Debug.Log ("At " +  timeStamp);
         Debug.Log ("GameObject " + gOName + " has encountered an error");
         Debug.Log ("inside the " + cOName + " component while using the " + methodName + " function");
         Debug.Log (additionalInfo);
         Debug.Log ("<----------- END MESSAGE ----------->");
     }
 }

and heres how I'm trying to call it:

 ErrorLog(gameObject, WhateverClass, "GetKeyCode", "NONE");


The problem is that it returns this in the editor:

 Expression denotes a `type', where a `variable', `value' or `method group' was expected

I've tried using typeOf on the class name. but it didnt seem to change anything. Does anybody know how I can make this work?

Comment
Add comment · Show 2
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 AmazingMrBrock · Jul 01, 2015 at 08:28 PM 0
Share

I was able to get it working but not how I want it to work. I cant call the class itself I had to change the error log so that the functionality is in a function called error message. I think instantiate it into the class I want to call it from and call errorLog.Error$$anonymous$$essage(); This is less than ideal and I need to learn how to make it work more properly. I'm not totally sure of all the ways I can use a class.

avatar image Jake-L · Jul 02, 2015 at 06:24 PM 0
Share

What about having a regular class (no $$anonymous$$onobehaviour) with a static method in it? You then can call it from anywhere anytime to write formatted output to the console. Isn't that exactly what you want?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jake-L · Jul 01, 2015 at 07:26 PM

Your parameter "relevantComponent" is a string and you try to pass a class. Either change the parameter to "object relevantComponent" or call it with WhateverClass.GetType().Name.

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 AmazingMrBrock · Jul 01, 2015 at 07:44 PM 0
Share

It still just gives me the same error

avatar image AmazingMrBrock · Jul 01, 2015 at 08:00 PM 0
Share

It appears the problem is happening with gameobject.

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

22 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

declaring unknown script components under a empty variable 0 Answers

Create a method that gets called everytime something happens, passing a Transform component to it 1 Answer

I can't use Rigidbody2D in my scripts, I can't find rigidbody2d in my script 3 Answers


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