Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8759159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:43:54+00:00 2026-06-13T14:43:54+00:00

For a Unity3d game I’m working on, I have a situation where I want

  • 0

For a Unity3d game I’m working on, I have a situation where I want a read/writeable property with a trivial getter, but a setter which does some more work. My code looks like this:

// IColor.cs
interface IColor {
    Color colorPainted { get; set; }
}

// Player.cs
public class Player : Monobehaviour, IColor {
    // ...
    public Color colorPainted {
        get { }
        set {
            colorPainted = value;
            // some other code
        }
     // ...
    }
}

I’m not sure what to do about the get part, though. I can’t return colorPainted;, because that causes a stack overflow. The code as written won’t compile because I’m not returning a value.

I’m no C# wizard, but it seems like I’d need to have a _colorPainted backing variable, and provide access to that through the get and set. This seems kinda verbose, though — is there a better way to do it? In Objective-C, I’d simply leave the getter unimplemented, but that doesn’t seem to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:43:55+00:00Added an answer on June 13, 2026 at 2:43 pm

    Unfortunately in C# there’s no way around it. You need to provide a backing field for the property:

    // Player.cs
    
    private Color _colorPainted;
    
    public class Player : Monobehaviour, IColor {
        // ...
        public Color colorPainted {
            get { return _colorPainted; }
            set {
                _colorPainted = value;
                // some other code
            }
         // ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working in the latest Unity3d 3.5 if it matters. If I have a set
I have been using C# with Unity3d for a few years now, but am
I have read all the documentation I found on how to integrate Unity3D projects
I have code in a .dll that a game in unity3d uses to connect
I want to dev some 2D game for mobile using Unity3d (iPhone & Android)
I have created the game in unity3d IOS. GUI buttons are changed their position
I have a game developed in Unity3d and I export it to be in
I have been trying for almost a week to install a Unity3d app/game on
I am working with Unity3d to create an iPhone game. Because iPhone is highly
I am trying to create a game for iPhone, iPad and Android in unity3d.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.